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
MS Access Where to put the code to calculate a field using data from a record selected in a subform
How to add country flags near username on the forum topics?
SSRS 2005 - Multiple IIF Statement
SQL Query - Syntax ( SQL 2005 / 2008 )
Windows Server Cannot Update Error number: 0x8024D007
Adding attachments to an Access form during dataentry
Lookup to return all columns to the right in excel
Win98SE Root Hub Woes
Set SelectedValue of DropdownList in EditItemTemplate of Gridview. Visual Studio 2005.
Showsound icon in notification area in Windows 7