Help with code to run query and test a field in the record

K

Kate

Tried the following and get the message too few parameters
expected 3. The following statement gets highlighted:

Set rs = db.OpenRecordset("QueryAv")

Any idea? Thanks


Dim db As DAO.Database
Dim rs As DAO.Recordset

Set db = CurrentDb()
Set rs = db.OpenRecordset("QueryAv")

If rs![Booking ID] = 1 Then
DoCmd.OpenForm "SINGLE BOOKING DETAIL"
End If

rs.Close : Set rs = Nothing
Set db = Nothing
 
V

Van T. Dinh

Post the SQL String of your QueryAv.

Do you use Parameters in this Query?

If you do, you need to resolve the Parameters before passing to JET for
processing.

--
HTH
Van T. Dinh
MVP (Access)


Kate said:
Tried the following and get the message too few parameters
expected 3. The following statement gets highlighted:

Set rs = db.OpenRecordset("QueryAv")

Any idea? Thanks


Dim db As DAO.Database
Dim rs As DAO.Recordset

Set db = CurrentDb()
Set rs = db.OpenRecordset("QueryAv")

If rs![Booking ID] = 1 Then
DoCmd.OpenForm "SINGLE BOOKING DETAIL"
End If

rs.Close : Set rs = Nothing
Set db = Nothing

MVP [MS Access]
 
T

tina

hi Van.
Kate did post the SQL, in a separate thread 3:59 pm this date, subject line:
I'm struggling with my limited knowledge of code.
i posted an answer, but maybe you'll come up with something better on
looking at it?
tina :)


Van T. Dinh said:
Post the SQL String of your QueryAv.

Do you use Parameters in this Query?

If you do, you need to resolve the Parameters before passing to JET for
processing.

--
HTH
Van T. Dinh
MVP (Access)


Kate said:
Tried the following and get the message too few parameters
expected 3. The following statement gets highlighted:

Set rs = db.OpenRecordset("QueryAv")

Any idea? Thanks


Dim db As DAO.Database
Dim rs As DAO.Recordset

Set db = CurrentDb()
Set rs = db.OpenRecordset("QueryAv")

If rs![Booking ID] = 1 Then
DoCmd.OpenForm "SINGLE BOOKING DETAIL"
End If

rs.Close : Set rs = Nothing
Set db = Nothing

MVP [MS Access]
 
V

Van T. Dinh

Yes.

There are 3 Parameters that need to be resolved before passing the SQL
String to JET for processing. They are:

Forms![SINGLE BOOKING AVAILABILITY]!BookingDate
Forms![SINGLE BOOKING AVAILABILITY]!Combo8
Forms![SINGLE BOOKING AVAILABILITY]!Combo10

Note that JET Database Engine which process the SQL String does not know
anything about Forms or Controls on Form so these need to be replaced with
actual values before passing the SQL String to JET for processing.
 

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