Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL statement does not work

Status
Not open for further replies.

lwilly

Technical User
Apr 11, 2000
84
US
I am trying to find a record in a table using an SQL statement in code.
Dim db As Database
Dim rst As Recordset
Dim strSQL As String
Dim strDate As String
Dim strTime As String

strDate = "#" & Me.Indate & "#"
strTime = "#" & Me.Intime & "#"

strSQL = "SELECT [order],[Date],[Time],[dpmt] FROM [Data2]"
strSQL = strSQL & "WHERE [Order] = '" & Me.order & "'"
strSQL = strSQL & " AND [time] = " & strTime
strSQL = strSQL & " AND [date] = " & strDate
strSQL = strSQL & " ORDER BY Data2.Date, Data2.Time"

Set rst = db.OpenRecordset(strSQL)

When run, I get an error msg. "Run Time Error 91"
"Object Variable or With Block Variable not set"

When I copy from the debug window and paste into query it works fine.

Any suggestions?
 
cut and paste ALL the code you're using.
from the code above there are no errors.

you probably have a IF statement without END IF at the end or the like.

HTH

PsychPt@Hotmail.com
 
Thank you braindead2, I think I'll change my name to braindead3.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top