'Code sample vb6 connecting with Ms-Access 2007/2010
'Exemplo vb6 conectando com Ms-Access 2007/2010
'--------------------------------------------------------
Global sDirInstall
Global sMyDB As String
'---------------------------------------------------------
Sub UserInfo()
'Marcar referência:
'PROJECT -> REFERENCE: Microsoft ActiveX Data Objects 2.8 Library
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Set con = New ADODB.Connection
Set rs = New ADODB.Recordset
sDirInstall = App.Path
sMyDB = sDirInstall & "USER.accdb"
con.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & sMyDB & ";Persist Security Info=False;Jet OLEDBDatabase Password="
rs.Index = "Primarykey"
rs.CursorLocation = adUseServer
rs.Open ("tb_User"), con, adOpenDynamic, adLockOptimistic, adCmdTableDirect
Do While Not rs.EOF
MsgBox rs.Fields("Userid") & " - " & rs.Fields("Nome")
rs.MoveNext
Loop
rs.Seek Array("NewUser"), adSeekMinEQ
If rs.EOF Then
rs.AddNew
rs.Fields("Userid") = "NewUser"
rs.Fields("Nome") = "USER NEW"
rs.Update
MsgBox "1 user added!"
Else
rs.Fields("Nome") = "USER NEW " & Now()
rs.Update
MsgBox "1 user changed!"
End If
rs.Close
con.Close
End Sub
----------------------------------------------------------
Saudações/Saludos/Regards,
HENDELCWB