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
SBS 2008 VPN Help Required
IIS 7.0 Worker process crashes due to ODP.NET?
SBS2003 exchange error
Merge Replication initialization error
In Access 2007, need a VBA function to test external database table to see if it is empty
i'm getting a "RUNTIME ERROR 3167", plz help!
MBOX TO PST
Format Datagrid
How to create a Form for data view
NTBACKUP scheduled backup fails - VSS problem?