Click to See Complete Forum and Search --> : SQL


Goose
September 22nd, 1999, 07:15 AM
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

shanep
September 27th, 1999, 02:46 AM
Doublecheck your connection string.

Error 3146 means your not connected to the database.

September 27th, 1999, 08:40 AM
Dim QD As QueryDef
.
.
.
Set GetListsCursor.QD = QD
why dont you chance the name of the querydef from QD to other name.