Passing parms to a query?

B

Brian

If I have a query such as :
PARAMETERS NEWID IEEEDouble;
UPDATE AVAILABILITY SET AVAILABILITY.[Booking ID] = NewID
WHERE (((AVAILABILITY.BookingDate)=Forms![SINGLE BOOKING
AVAILABILITY]!BookingDate) And ((AVAILABILITY.Period)
=Forms![SINGLE BOOKING AVAILABILITY]!Combo8) And
((AVAILABILITY.Room)=Forms![SINGLE BOOKING AVAILABILITY]!
Combo10));

and in my macro I want to pass a parameter then what
would be the format?

i.e. where would it go in the following code:
stDocName = "UpdateAv"
DoCmd.OpenQuery stDocName, acNormal, acEdit

Thanks in advance
 
N

Nikos Yannacopoulos

Brian,

It depends where the parameter values come from.

If, for example, they are read from controls on an open form, then the
easiest way is to add references to them in the Update To expressions in
your saved query, like
Forms!FormName!ControlName

If, on the other hand, the parameter values are only available in code, I
would build the SQL expression for the update query in the code, where it
can read the parameters value as well as read values for the Where clause,
and execute it from within the code, without using a saved query, something
like:

strSQL = "UPDATE AVAILABILITY SET AVAILABILITY.[Booking ID] = '" & NewID &
"'"
strSQL = strSQL & " WHERE (((AVAILABILITY.BookingDate)="
strSQL = strSQL & Forms![SINGLE BOOKING AVAILABILITY]!BookingDate)
strSQL = strSQL & " And ((AVAILABILITY.Period) ="
strSQL = strSQL & " Forms![SINGLE BOOKING AVAILABILITY]!Combo8 & ")"
strSQL = strSQL & " And ((AVAILABILITY.Room)="
strSQL = strSQL & Forms![SINGLE BOOKING AVAILABILITY]!> Combo10 & "));"
DoCmd.RunSQL (strSQL)

Just mind the use of quotes around form control references, depending on
whether they are text or not. Above I have assumed that only the NewID field
is text.

HTH,
Nikos
 

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