I have script that creates a pass through query using a connection string and a password. It works on first connection attempt: fails until the user enters the correct password. If the connection string is lost or the user needs to renter it for any reason, it will succeed no matter what password is passed through the connection string.
I've tried created named queryDefs and removing them, unique and non-unique. If this is the way it has to be, I'll work with it, but I don't like not understanding what's going on, so if anyone has any insight, that would be great. Thanks!
Dim db As DAO.Database, qDef As QueryDef, rst As DAO.Recordset
Set db = CurrentDb
Set qDef = db.CreateQueryDef(vbNullString)
With qDef
.Connect = connStr
.sql = sql
.ReturnsRecords = True
Set rst = .OpenRecordset(dbOpenSnapshot, dbSQLPassThrough)
End With
If readAll Then
With rst
If Not .EOF And Not .BOF Then
.MoveLast
.MoveFirst
End If
End With
End If
Set PassThroughRecordset = rst