Querydef ODBC connection problem

jonomac

Registered User.
Local time
Today, 01:55
Joined
Jul 6, 2005
Messages
22
Hi,
I am using DAO and seem to have a problem using a pass through query with an ODBC link to a sybase server...

If an incorrect ID and PW are entered for the first time into some text boxes I have set up and then the query is run for the first time it will return no results as expected as no ODBC link can be established. Then if on a second attempt the ID and PW have been entered correctly, the query still refuses to pull back data.

The same also applies in reverse, ie, if an incorrect ID and PW have been typed into the text boxes AFTER a successful run, the query will still pull back the data from the sybase server as if the correctly run link is still in existence.

I reset the ODBC connectionstring of the query to "ODBC;" after each run for security purposes so that you shouldn't be able to run it again without the username and password in the textboxes...

How do I close the connection that seems to have been established even tho I am resetting the connection string each time and setting the querydef to nothing?

A quick cut of the code follows: (yes I do use strings normally, the me.txtServer etc are for illustration!)

Code:
Private Sub cmdView_Click()
Dim qdf As QueryDef
Set qdf = CurrentDb.QueryDefs(Me.cmbReport)
qdf.Connect = "ODBC;DSN=" & Me.txtServer & ";UID=" & Me.txtUsername & ";PWD=" & Me.txtPassword

DoCmd.OpenQuery Me.cmbReport, acViewNormal

qdf.Connect = "ODBC;"
Set qdf = Nothing
End Sub

Many thanks!
 
Last edited:

Users who are viewing this thread

Back
Top Bottom