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
The MAPI call 'OpenMsgStore' failed with the following error, mailbox store cannot be accessed
one continuous page and want no page breaks
E-mail addresses missing from Outlook cache
MS SQL Server 2008 Express modifying field sizes
VBS Excel script
read xml object
Putting a variable into SQL
Multiple Asset tracking per month / Per year
sound driver
Terminal Services 2008