-
SQL
Hi All
I am connecting to SQlServer using DAO.
The following code selects all the records.
Public Sub GetLists(Connect As tConnect)
' Returns any number of records.
Set GetListsCursor = New tCursor
Connect.RoutineName = "GetLists"
Dim QD As QueryDef
Set QD = Connect.DB.CreateQueryDef("", "Select NAME from Staff where Administrator = 'Y' UNION Select SHORTNAME FROM SECTORDETAILS WHERE ALPHANUMCODE NOT LIKE 'C%' AND ALPHANUMCODE NOT LIKE 'N%' UNION SELECT '#' +LISTNAME FROM USERSHARELIST WHERE UserID = " & TEmp_No & " UNION SELECT '*' +NAME FROM GROUPDETAILS ")
Set GetListsCursor.Connect = Connect
Set GetListsCursor.QD = QD
Set GetListsCursor.RS = GetListsCursor.QD.OpenRecordset(dbOpenSnapshot, dbForwardOnly And dbReadOnly)
End Sub
It returns the following error:
?err.Description
ODBC--call failed.
?err.Number
3146
I have no idea why.
Thanx
-
Re: SQL
Doublecheck your connection string.
Error 3146 means your not connected to the database.
-
Re: SQL
Dim QD As QueryDef
.
.
.
Set GetListsCursor.QD = QD
why dont you chance the name of the querydef from QD to other name.