I. Form Layout Single Record Dengan Binding Type Ado Data Control
I. Form Layout Single Record Dengan Binding Type Ado Data Control
Coding :
Private Sub Form_Unload(Cancel As Integer)
Screen.MousePointer = vbDefault
End Sub
Private Sub datPrimaryRS_Error(ByVal ErrorNumber As Long, Description As String, ByVal Scode As
Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, fCancelDisplay As
Boolean)
'This is where you would put error handling code
'If you want to ignore errors, comment out the next line
'If you want to trap them, add code here to handle them
MsgBox "Data error event hit err:" & Description
End Sub
Exit Sub
AddErr:
MsgBox Err.Description
End Sub
datPrimaryRS.Recordset.UpdateBatch adAffectAll
Exit Sub
UpdateErr:
MsgBox Err.Description
End Sub
Jika kita mengklik tombol update maka secara otomatis data yang akan diganti akan terganti, jadi
tidak ada pilihan untuk membatalkan perubahan data.
UPDATE : Tombol update untuk merubah isi suatu record pada suatu data
DELETE : Tombol delete untuk menghapus suatu record pada suatu data
REFRESH : Tombol refresh untuk mengembaikan ke record 1
CLOSE : Tombol Close untuk menutup dialog box/mengakhiri running program
mbDataChanged = False
End Sub
Exit Sub
AddErr:
MsgBox Err.Description
End Sub
EditErr:
MsgBox Err.Description
End Sub
Private Sub cmdCancel_Click()
On Error Resume Next
SetButtons True
mbEditFlag = False
mbAddNewFlag = False
adoPrimaryRS.CancelUpdate
If mvBookMark > 0 Then
adoPrimaryRS.Bookmark = mvBookMark
Else
adoPrimaryRS.MoveFirst
End If
mbDataChanged = False
End Sub
adoPrimaryRS.UpdateBatch adAffectAll
If mbAddNewFlag Then
adoPrimaryRS.MoveLast 'move to the new record
End If
mbEditFlag = False
mbAddNewFlag = False
SetButtons True
mbDataChanged = False
Exit Sub
UpdateErr:
MsgBox Err.Description
End Sub
adoPrimaryRS.MoveFirst
mbDataChanged = False
Exit Sub
GoFirstError:
MsgBox Err.Description
End Sub
adoPrimaryRS.MoveLast
mbDataChanged = False
Exit Sub
GoLastError:
MsgBox Err.Description
End Sub
Exit Sub
GoNextError:
MsgBox Err.Description
End Sub
Exit Sub
End Sub
Penjelasan :
Maka akan muncul tombol Update dan Cancel seperti gambar dibawah ini :
Coding :
Dim WithEvents adoPrimaryRS As Recordset
Private DoingRequery As Boolean
Public Event MoveComplete()
DataMembers.Add "Primary"
End Sub
Penjelasan :
Pada Form Single Record dengan Binding Type Class, terdapat class module.
Exit Sub
AddErr:
MsgBox Err.Description
End Sub
datPrimaryRS.Recordset.UpdateBatch adAffectAll
Exit Sub
UpdateErr:
MsgBox Err.Description
End Sub
End Sub
UPDATE : Tombol update untuk merubah isi suatu record pada suatu data
DELETE : Tombol delete untuk menghapus suatu record pada suatu data
REFRESH : Tombol refresh untuk mengembaikan ke record 1
CLOSE : Tombol Close untuk menutup dialog box/mengakhiri running program
Coding :
Dim WithEvents adoPrimaryRS As Recordset
Dim mbChangedByCode As Boolean
Dim mvBookMark As Variant
Dim mbEditFlag As Boolean
Dim mbAddNewFlag As Boolean
Dim mbDataChanged As Boolean
Exit Sub
AddErr:
MsgBox Err.Description
End Sub
Exit Sub
RefreshErr:
MsgBox Err.Description
End Sub
EditErr:
MsgBox Err.Description
End Sub
Private Sub cmdCancel_Click()
On Error Resume Next
End Sub
adoPrimaryRS.UpdateBatch adAffectAll
If mbAddNewFlag Then
adoPrimaryRS.MoveLast 'move to the new record
End If
mbEditFlag = False
mbAddNewFlag = False
SetButtons True
mbDataChanged = False
Exit Sub
UpdateErr:
MsgBox Err.Description
End Sub
adoPrimaryRS.MoveFirst
mbDataChanged = False
Exit Sub
GoFirstError:
MsgBox Err.Description
End Sub
adoPrimaryRS.MoveLast
mbDataChanged = False
Exit Sub
GoLastError:
MsgBox Err.Description
End Sub
Exit Sub
GoNextError:
MsgBox Err.Description
End Sub
Exit Sub
GoPrevError:
MsgBox Err.Description
End Sub
End Sub
FUNGSI MASING-MASING TOMBOL :
ADD : Tombol add untuk menambah suatu record pada suatu data.
Sehigga akan tertampil 1 record kosong pada form tersebut.
DELETE : Tombol delete untuk menghapus suatu record pada suatu data
REFRESH : Tombol refresh untuk mengembaikan ke record 1
CLOSE : Tombol Close untuk menutup dialog box/mengakhiri running program
Coding :
Dim WithEvents adoPrimaryRS As Recordset
DataMembers.Add "Primary"
End Sub
Penjelasan :
SMK TELKOM SANDHY PUTRA MALANG Page 22
Pada Form Single Record dengan Binding Type Class, terdapat class module.
datPrimaryRS.Visible = False
With MSHFlexGrid1
.Redraw = False
' set grid's column widths
.ColWidth(0) = -1
.ColWidth(1) = -1
.ColWidth(2) = -1
.ColWidth(3) = -1
.ColWidth(4) = -1
.ColWidth(5) = -1
.ColWidth(6) = -1
.AllowBigSelection = False
.FillStyle = flexFillSingle
.Redraw = True
End With
End Sub
End Sub
xdn = X
ydn = Y
m_iDragCol = -1 ' clear drag flag
m_bDragOK = True
End Sub
End Sub
m_bDragOK = False
End Sub
.MSHFlexGrid1.Move MARGIN_SIZE, _
MARGIN_SIZE, _
sngScaleWidth - (2 * MARGIN_SIZE), _
sngButtonTop - (2 * MARGIN_SIZE)
End With
Exit Sub
Form_Resize_Error:
' avoid error on negative values
Resume Next
End Sub
Private Sub cmdClose_Click()
Unload Me
End Sub
Penjelasan :
MS HflexGrid dengan Binding Type Ado Data Control ini merupakan Form yang digunakan sebagai
Report. Jadi, tidak terdapat button untuk merubah, menghapus atau menambah data. Kita hanya bisa
melihat Report nya saja.
Coding :
Private Const MARGIN_SIZE = 60 ' in Twips
' variables for data binding
Private datPrimaryRS As ADODB.Recordset
With MSHFlexGrid1
.Redraw = False
' set grid's column widths
.ColWidth(0) = -1
.ColWidth(1) = -1
.ColWidth(2) = -1
.ColWidth(3) = -1
.ColWidth(4) = -1
.ColWidth(5) = -1
.ColWidth(6) = -1
.AllowBigSelection = False
.FillStyle = flexFillSingle
.Redraw = True
End Sub
Dim i As Integer
DoColumnSort
End Sub
Sub DoColumnSort()
'-------------------------------------------------------------------------------------------
' does Exchange-type sort on column m_iSortCol
'-------------------------------------------------------------------------------------------
With MSHFlexGrid1
.Redraw = False
.Row = 1
.RowSel = .Rows - 1
.Col = m_iSortCol
.Sort = m_iSortType
.FillStyle = flexFillRepeat
.Col = 0
.Row = .FixedRows
.RowSel = .Rows - 1
.ColSel = .Cols - 1
.CellBackColor = &HFFFFFF
' grey every other row
Dim iLoop As Integer
For iLoop = .FixedRows + 1 To .Rows - 1 Step 2
.Row = iLoop
.Col = .FixedCols
.ColSel = .Cols() - .FixedCols - 1
.CellBackColor = &HC0C0C0 ' light grey
Next iLoop
.FillStyle = flexFillSingle
End Sub
.MSHFlexGrid1.Move MARGIN_SIZE, _
MARGIN_SIZE, _
sngScaleWidth - (2 * MARGIN_SIZE), _
sngButtonTop - (2 * MARGIN_SIZE)
End With
Exit Sub
Form_Resize_Error:
' avoid error on negative values
Resume Next
End Sub
Private Sub cmdClose_Click()
Unload Me
End Sub
Penjelasan :
MS HflexGrid dengan Binding Type Ado Code ini merupakan Form yang digunakan sebagai Report.
Jadi, tidak terdapat button untuk merubah, menghapus atau menambah data. Kita hanya bisa melihat
Report nya saja.
Exit Sub
AddErr:
MsgBox Err.Description
End Sub
datPrimaryRS.Recordset.UpdateBatch adAffectAll
Exit Sub
UpdateErr:
MsgBox Err.Description
End Sub
Coding :
Dim WithEvents adoPrimaryRS As Recordset
Dim mbChangedByCode As Boolean
Dim mvBookMark As Variant
Dim mbEditFlag As Boolean
Dim mbAddNewFlag As Boolean
Dim mbDataChanged As Boolean
mbDataChanged = False
End Sub
Exit Sub
AddErr:
MsgBox Err.Description
End Sub
EditErr:
MsgBox Err.Description
End Sub
Private Sub cmdCancel_Click()
On Error Resume Next
SetButtons True
mbEditFlag = False
mbAddNewFlag = False
adoPrimaryRS.CancelUpdate
If mvBookMark > 0 Then
End Sub
adoPrimaryRS.UpdateBatch adAffectAll
If mbAddNewFlag Then
adoPrimaryRS.MoveLast 'move to the new record
End If
mbEditFlag = False
mbAddNewFlag = False
SetButtons True
mbDataChanged = False
Exit Sub
UpdateErr:
MsgBox Err.Description
End Sub
adoPrimaryRS.MoveFirst
mbDataChanged = False
Exit Sub
GoFirstError:
MsgBox Err.Description
End Sub
adoPrimaryRS.MoveLast
mbDataChanged = False
Exit Sub
GoLastError:
MsgBox Err.Description
End Sub
Exit Sub
GoNextError:
MsgBox Err.Description
End Sub
Exit Sub
GoPrevError:
MsgBox Err.Description
End Sub
Coding :
Private WithEvents PrimaryCLS As clsOrders
Dim mbChangedByCode As Boolean
Dim mvBookMark As Variant
Dim mbEditFlag As Boolean
Dim mbAddNewFlag As Boolean
Dim mbDataChanged As Boolean
Exit Sub
AddErr:
MsgBox Err.Description
End Sub
EditErr:
MsgBox Err.Description
End Sub
Private Sub cmdCancel_Click()
On Error Resume Next
PrimaryCLS.Cancel
SetButtons True
End Sub
PrimaryCLS.Update
SetButtons True
Exit Sub
UpdateErr:
MsgBox Err.Description
End Sub
PrimaryCLS.MoveFirst
mbDataChanged = False
Exit Sub
GoFirstError:
MsgBox Err.Description
End Sub
PrimaryCLS.MoveLast
mbDataChanged = False
Exit Sub
GoLastError:
MsgBox Err.Description
End Sub
PrimaryCLS.MoveNext
Exit Sub
GoNextError:
MsgBox Err.Description
End Sub
PrimaryCLS.MovePrevious
Exit Sub
GoPrevError:
MsgBox Err.Description
End Sub
Penjelasan :
Pada Form Layout Master/Detail dengan Binding Type Class, terdapat class module.