borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Next Topic (Help with ado.recordset.filter syntax, please!) New Topic New Poll Post Reply
AndreaVB Forum : Database : ADO Connection
Poster Message
djsmiffy
Level: Trainee

Registered: 12-11-2007
Posts: 1

icon ADO Connection

Hi hope someone can help

I'm trying to use ADO in access to lookup product info from a few tables. The table to use depends on the choices the user selects in three combo boxes. I just can't get access any of the tables with my code:

Private Sub PopulateGrade()
    Dim cnn1 As ADODB.Connection
    Dim GdRs As New ADODB.Connection
    Dim SQLst As String
    
    Set cnn1 = CurrentProject.Connection
    
    SQLst = "SELECT Product, Flute FROM "
    SQLst = SQLst & ComboMill.Value & ComboBoard.Value
    SQLst = SQLst & " WHERE (((Flute)='"
    SQLst = SQLst & ComboFlute.Value & "'"
        
    
    GdRs.Open SQLst
End sub

ComboMill, ComboBoard and ComboFlute's row source type are set to value list and contain the supplier name, general material type and material thickness. Combining ComboMill and ComboBoard gives the table name (or should).

When I run the code I get:

Run-Time Error '-2147467259(80004005)':

[Microsoft][ODBC Driver Manager]Data source name not found and no default driver specified.

I need to know if it's looking for the data source in the right place as the name should be correct and what's a default driver and how do you specify one.

Any help you can offer is most welcome as this is driving me nutts  

Thanks Dave

12-11-2007 at 07:26 AM
View Profile Send Email to User Show All Posts | Quote Reply
stickleprojects
Level: Moderator


Registered: 09-09-2002
Posts: 904
icon Re: ADO Connection

Hi
Have you checked the sql statement is correct? No spaces inthe middle of the tables names, etc.?


____________________________
Build it better, faster, quicker, easier.. then fix it (non-offical MS mission statement)

21-11-2007 at 07:57 AM
View Profile Send Email to User Show All Posts | Quote Reply
yronium
Level: Moderator


Registered: 14-04-2002
Posts: 912
icon Re: ADO Connection

Hello. In addition to stickleproject's tips, you got to ensure the connection is open, before attempting to retrieve records from the db. And there's no need to declare a local ADODB.Connection variable: you can simply specify the global connection to the recordset, and it will use it. But you GOT to specify the connection for the recordset to use to be open:
    ' assumes that the CurrentProject.Connection object is a valid and currently open connection
    GdRs.Open SQLst, cnn1

    ' (If the connection is open, this also works, and it doesn't need any additional variable declaration)
    ' GdRs.Open SQLst, CurrentProject.Connection

And more, you better should specify the cursor type:
    GdRs.Open SQLst, cnn1, adOpenForwardOnly

... and the lock type...
    GdRs.Open SQLst, cnn1, adOpenForwardOnly, adLockReadOnly

... and the type of request too, in order to speed up ADO's retrieval work
    GdRs.Open SQLst, cnn1, adOpenForwardOnly, adLockReadOnly, adCmdText

Well, in fact you better deepen ADO's usage. Maybe you would appreciate looking this sample project I posted time ago.

Hope it helps.

____________________________
Real Programmer can count up to 1024 on his fingers

21-11-2007 at 04:52 PM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : Database : ADO Connection
Next Topic (Help with ado.recordset.filter syntax, please!) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder