Microsoft
Software
Hardware
Network
Question : Using a date varible in where clause of SQL
Below is code for using a date varible in a SQL where clause. The date is coming from form frm_timeadj field text0. If I hardcode the date it works, with code below, I get no records error.
Private Sub Command7_Click()
Dim qdate As Date
Dim ID As String
Dim rs As DAO.Recordset
Dim db As Database
Dim rs2 As DAO.Recordset
ID = Form_MainForm.Text37
qdate = Form_frm_TimeAdj.Text0
Set db = CurrentDb
Set rs = db.OpenRecordset("SELECT hours FROM Sub_op_Time WHERE time_date = " & qdate & " and act_num = 11 and act_type_num = 1")
Set rs2 = db.OpenRecordset("SELECT num_hours FROM Inspector_List WHERE user_ID = '" & ID & "'")
If Form_frm_TimeAdj.Text8 > rs2!num_hours Then
MsgBox "Exceeded maximum Straight Time Hours for Day"
Else
rs.Edit
rs!Hours = rs2!num_hours - Form_frm_TimeAdj.Text8
rs.Update
End If
rs.Close
rs2.Close
Set rs = Nothing
Set rs2 = Nothing
Set db = Nothing
End Sub
Answer : Using a date varible in where clause of SQL
Try this:
Set rs = db.OpenRecordset("SELECT hours FROM Sub_op_Time WHERE time_date = #" & qdate & "# and
Random Solutions
Removing Logon screen in Windows XPe
Need to Capture LPT1, FROM MULTIPLE PRINT JOBS, and save them all in one file
Using MS Access to open web server MySQL database - is it possible?
No 2010 OWA Access - Side by side Exchange Servers (temporarily)
Exporting Access table to Excel using VBA
How do I parameterise a Union query so that a prompt it not issued each time it runs...
Boot.ini
How to create a "Link Label"?
Moving mailboxes from SBS 2003 to Exchange 2007
Access 2000 Multi User Help