VB6 - ODBC connection problem
Posted on 2009-02-10
I have a vb6 project, with a command button and a listbox on a form. I have linked the refference DAO 3.6 to the project. I want co connect to an access database and receive some records from there via ODBC.
Now i have the following code attached to Command1:
Private Sub Command1_Click()
Dim ws As Workspace
Dim db As Database
Dim strConnection As String
Dim rs As Recordset
Dim DatabaseName As String
Dim UserName As String
Dim UserPassword As String
DatabaseName = "c:\Firewall.mdb"
UserName = ""
UserPassword = ""
Set ws = DBEngine.Workspaces(0)
Let strConnection = "ODBC;DSN=" & DatabaseName & ";UID=" & UserName _
& ";PWD=" & UserPassword
Set db = ws.OpenDatabase("", False, False, strConnection)
Set rs = db.OpenRecordset("tbl_Clienti")
Do While Not rs.EOF
'Put the code here for what to do with the information.
'The field information can be access by the field name
'Or by the order number it is in the list (starting at 0)
' intString = rs.Field(1)
On the line: Set db = ws.OpenDatabase("", False, False, strConnection)
i get the following error message:
Run-time error '3151'
ODBC -- connection to 'c:\firewall.mdb' failed
Can you help me?