Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

VB6 - ODBC connection problem

Posted on 2009-02-10
3
Medium Priority
?
2,101 Views
Last Modified: 2013-12-20
Hello,
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:

Option Explicit
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
        List1.AddItem rs!Nume_Client
        'Or by the order number it is in the list (starting at 0)
'        intString = rs.Field(1)
        rs.MoveNext
    Loop
End Sub

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?
0
Comment
Question by:Cristi_E
3 Comments
 
LVL 4

Author Comment

by:Cristi_E
ID: 23609174
Any ideeas?
0
 
LVL 2

Accepted Solution

by:
Balajitr earned 750 total points
ID: 23609365
Try this line

Set db = ws.OpenDatabase(DatabaseName)
0
 
LVL 2

Assisted Solution

by:gandalf97
gandalf97 earned 750 total points
ID: 23636469
You might also want to double check to make sure the database exists and that the variables for the username and password contain what you think they should.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question