Connect VB6 to Msaccess

Asked

Viewed 154 times

0

I created a Msaccess Database and created a connection module. However, when the executable gives connection error. Someone has another example of how to connect VB6 to Msacess?

The code to my module:

Option Compare Database

Option Explicit
Public T As Connection
Public c As Recordset

Private Sub conexao()
    Set T = creatobject("adodb.connection")
    Set c = creatobject("adodb.recordset")
    T.OpenRecordset " provider = microsoft.jet.oledb.4.0;datasource = " + app.Path & "\alex.mdb"
End Sub

Private Sub desconexao()
    Set T = Nothing
    Set c = Nothing
End Sub
  • Hello. Try to print datasource = " + app.Path & "\alex.mdb" in a MsgBox and check the path is correct. The database has password?

  • has already done but continues to give error, the database has no password.

1 answer

1

Your connection function should be:

Private Sub conexao()
    Set T = creatobject("adodb.connection")
    Set c = creatobject("adodb.recordset")
    connString = microsoft.jet.oledb.4.0;datasource = " + app.Path & "\alex.mdb"
    T.Open connString // Abre a ligação para a base de dados
End Sub

Only after opening connection with the T.Open is that it will be able to perform operations in the BD.

  • So it worked out thanks to the tip,but I have a little problem which is code to select a field in the listbox and select if all fields?

  • @user7752 This doubt is not connected with the current question. I would suggest that you open a new question for your question. Do not forget to accept the answers that helped you in order to help future people with questions (see Help Center page

Browser other questions tagged

You are not signed in. Login or sign up in order to post.