Option Explicit
Public con As New ADODB.Connection
Public rs As New ADODB.Recordset
Public cmd As New ADODB.Command
Public sql As String
Public Sub Errror()
If Err.Number <> 0 Then MsgBox Err.Description, vbCritical, "Error"
End Sub
Public Sub eksekusi(sql As String)
Set rs = New Recordset
rs.Open sql, con, adOpenDynamic, adLockOptimistic
End Sub
Public Sub konek()
On Error GoTo erroro
Dim strpath As String
strpath = App.Path & "\bbm.mdb"
con = New Connection
con.Open ("Provider = Microsoft.Jet.OLEDB.4.0; Data Source = " & Trim(strpath) & "")
erroro: Errror
End Sub
Public Function Valid(frm As Form, bnan As Boolean) As Integer
On Error GoTo ada
Valid = 0
Dim ctl As Control
For Each ctl In frm.Controls
If TypeOf ctl Is TextBox Then
If bnan Then
If ctl.Text = "" Then
Valid = Valid + 1
ctl.SetFocus
Exit For
End If
Else
ctl.Text = ""
End If
End If
Next
ada: Errror
End Function
Public Sub tampildg(dg As DataGrid, ad As Adodc, query As String)
On Error GoTo ada
Dim i As Integer
With ad
.ConnectionString = con
.RecordSource = query
.Refresh
Set dg.DataSource = ad
.Caption = "Banyaknya Data: " & ad.Recordset.RecordCount
End With
For i = 0 To dg.Columns.Count - 1
dg.Columns(i).Caption = Replace(dg.Columns(i).Caption, "_", " ", 1, Len(dg.Columns(i).Caption), vbTextCompare)
dg.Columns(i).Caption = StrConv(dg.Columns(i).Caption, vbProperCase)
Next
ada: Errror
End Sub
Sunday, November 4, 2007
Connection to database Ms. Access
Subscribe to:
Posts (Atom)