27 Sept 2012

Menginput Data dengan MSFlexGrid

Unknown | 10:52 |
Setelah memposting menginput data dengan DataGrid, kali ini saya akan memposting artikel tentang menginput data dengan MSFlexGrid

source code :
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset

Private Sub cmdSave_Click()
For i = 1 To MSHFlexGrid1.Rows - 1
If MSHFlexGrid1.TextMatrix(i, 0) <> "" Then
rs.AddNew
rs(0) = MSHFlexGrid1.TextMatrix(i, 0)
rs(1) = MSHFlexGrid1.TextMatrix(i, 1)
rs(2) = MSHFlexGrid1.TextMatrix(i, 2)
rs(3) = MSHFlexGrid1.TextMatrix(i, 3)
rs(4) = MSHFlexGrid1.TextMatrix(i, 4)
rs(5) = MSHFlexGrid1.TextMatrix(i, 5)
rs(6) = MSHFlexGrid1.TextMatrix(i, 6)
rs.Update
Else
Exit For
End If
Next
End Sub

Private Sub Form_Load()
With MSHFlexGrid1
.TextMatrix(0, 0) = "Kolom 1"
.TextMatrix(0, 1) = "Kolom 2"
.TextMatrix(0, 2) = "Kolom 3"
.TextMatrix(0, 3) = "Kolom 4"
.TextMatrix(0, 4) = "Kolom 5"
.TextMatrix(0, 5) = "Kolom 6"
.TextMatrix(0, 6) = "Kolom 7"
End With

Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset

conn.Provider = "Microsoft.Jet.OleDB.4.0"
conn.Open App.Path & "\nwind.mdb"

rs.Open "Customers", conn, adOpenDynamic, adLockOptimistic

End Sub

Private Sub MSHFlexGrid1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case vbKeyReturn, vbKeyTab
'---pindah ke cell berikutnya
With MSHFlexGrid1
If .Col + 1 <= .Cols - 1 Then
.Col = .Col + 1
Else
If .Row + 1 <= .Rows - 1 Then
.Row = .Row + 1
.Col = 0
Else
.Row = 1
.Col = 0
End If
End If
End With
Case vbKeyBack
With MSHFlexGrid1
'---hapus karakter terakhir
If Len(.Text) Then
.Text = Left(.Text, Len(.Text) - 1)
End If
End With
Case Is < 32 '---selain alfabet ga bisa dimasukkin
Case Else
'---masukkan karakter ke flexgrid
MSHFlexGrid1.Text = MSHFlexGrid1.Text & Chr(KeyAscii)
End Select
End Sub
gambar hasil output :


selesay...
selanjutnya saya akan memposting bagaimana cara menginput Data dengan TrueDBGrid  :D :lol: :-)
jadi ikuti terus Blog ini ....


Ditulis Oleh : Unknown ~ kudo-share.blogspot.com

Anda sedang membaca sebuah artikel yang berjudul Menginput Data dengan MSFlexGrid, Semoga artikel tersebut bermanfaat untuk anda ....

:: Thank you for visiting ! ::

Post a Comment