Parameter Missing Expected 3

B

Brad

Thanks for taking the time to read my question.

My code stopped working and I'm not sure why.

I have a query with 3 criteria in it. I also have this code. When it gets
to Set qdf, and error pops up saying Too Few Parameters, Expected 3. There
are 3 parameters!

What's going on here?


Thanks for your help,

Brad

Code:

Dim dbs As Database, rst As Recordset, qdf As QueryDef
Set dbs = CurrentDb
Set qdf = dbs.OpenRecordset("qryAddNewBookingPossible")
'qdf.Parameters(0).Value = [Forms]![frmtblBookingAddNew]![tblBookingID]
qdf.Parameters(0).Value = [Forms]![frmtblBookingAddNew]![BookingRoomBooked]
qdf.Parameters(1).Value = [Forms]![frmtblBookingAddNew]![BookingStartDate]
qdf.Parameters(2).Value = [Forms]![frmtblBookingAddNew]![BookingEndDate]
Set rst = qdf.OpenRecordset()

Here's my sql:

SELECT [BookingStartDate]+[BookingStartTime] AS BookingStartDateTime,
[BookingEndDate]+[BookingEndTime] AS BookingEndDateTime,
tblBooking.tblBookingID, tblBooking.BookingRoomBooked,
Max(tblBooking.BookingSlot) AS MaxOfBookingSlot, tblBooking.BookingStartDate,
tblBooking.BookingEndDate
FROM tblBooking
GROUP BY [BookingStartDate]+[BookingStartTime],
[BookingEndDate]+[BookingEndTime], tblBooking.tblBookingID,
tblBooking.BookingRoomBooked, tblBooking.BookingStartDate,
tblBooking.BookingEndDate
HAVING
(((tblBooking.BookingRoomBooked)=[Forms]![frmtblBookingAddNew]![BookingRoomBooked])
AND
((tblBooking.BookingStartDate)>=[Forms]![frmtblBookingAddNew]![BookingStartDate])
AND
((tblBooking.BookingEndDate)<=[Forms]![frmtblBookingAddNew]![BookingEndDate]))
ORDER BY [BookingStartDate]+[BookingStartTime],
[BookingEndDate]+[BookingEndTime];
 
B

Brad

I took the criteria out of the query, and rem'ed out the parameter lines and
now I get 'Type Mismatch' err # 13 when I set qdf to a query.
 
M

Marshall Barton

You need to set qdf to the QueryDef, not to a recordset.

Set qdf = dbs.QueryDefs("qryAddNewBookingPossible")
 
B

Brad

You know, some days I swear that I bring my head to work, but forget my
brain...

Thanks Marshall.

Marshall Barton said:
You need to set qdf to the QueryDef, not to a recordset.

Set qdf = dbs.QueryDefs("qryAddNewBookingPossible")
--
Marsh
MVP [MS Access]

My code stopped working and I'm not sure why.

I have a query with 3 criteria in it. I also have this code. When it gets
to Set qdf, and error pops up saying Too Few Parameters, Expected 3. There
are 3 parameters!

Code:

Dim dbs As Database, rst As Recordset, qdf As QueryDef
Set dbs = CurrentDb
Set qdf = dbs.OpenRecordset("qryAddNewBookingPossible")
'qdf.Parameters(0).Value = [Forms]![frmtblBookingAddNew]![tblBookingID]
qdf.Parameters(0).Value = [Forms]![frmtblBookingAddNew]![BookingRoomBooked]
qdf.Parameters(1).Value = [Forms]![frmtblBookingAddNew]![BookingStartDate]
qdf.Parameters(2).Value = [Forms]![frmtblBookingAddNew]![BookingEndDate]
Set rst = qdf.OpenRecordset()

Here's my sql:

SELECT [BookingStartDate]+[BookingStartTime] AS BookingStartDateTime,
[BookingEndDate]+[BookingEndTime] AS BookingEndDateTime,
tblBooking.tblBookingID, tblBooking.BookingRoomBooked,
Max(tblBooking.BookingSlot) AS MaxOfBookingSlot, tblBooking.BookingStartDate,
tblBooking.BookingEndDate
FROM tblBooking
GROUP BY [BookingStartDate]+[BookingStartTime],
[BookingEndDate]+[BookingEndTime], tblBooking.tblBookingID,
tblBooking.BookingRoomBooked, tblBooking.BookingStartDate,
tblBooking.BookingEndDate
HAVING
(((tblBooking.BookingRoomBooked)=[Forms]![frmtblBookingAddNew]![BookingRoomBooked])
AND
((tblBooking.BookingStartDate)>=[Forms]![frmtblBookingAddNew]![BookingStartDate])
AND
((tblBooking.BookingEndDate)<=[Forms]![frmtblBookingAddNew]![BookingEndDate]))
ORDER BY [BookingStartDate]+[BookingStartTime],
[BookingEndDate]+[BookingEndTime];
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top