SQL and recordset Help (1 Viewer)

sam1fletcher

Registered User.
Local time
Today, 08:29
Joined
Jan 28, 2013
Messages
40
Hey All

got runtime error 3061 which i realised my sql code is wrong

Code:
Dim rs As DAO.Recordset
Dim sql As String
Dim ct As Integer
sql = "SELECT * FROM tblBookings WHERE (((tblBookings.Date_Start) Between [Forms]![frmMenu]![ArrivalDate] And [Forms]![frmMenu]![ArrivalDate]+29)) OR (((tblBookings.Date_End) Between [Forms]![frmMenu]![ArrivalDate] And [Forms]![frmMenu]![ArrivalDate]+29));"
Set rs = CurrentDb.OpenRecordset(sql)
With rs
.MoveFirst
.MoveLast
ct = .RecordCount
End With

Me.r11.Value = ct

This is meant to open a recordset that the records are between 2 dates from 2 textboxes on a form.

i think the sql is alittle dodgy can anybody see a problem

sam
 

mdlueck

Sr. Application Developer
Local time
Today, 03:29
Joined
Jun 23, 2011
Messages
2,631
You need to turn on/off your quoted SQL string when you bump into needing to refection control values.

Example
Code:
"SELECT * FROM [tablename] WHERE [cola] = " & Me.fldcola.Value & " AND [colb] > " & Me.fldcolb.Value
 

Users who are viewing this thread

Top Bottom