Help passing parameters 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
 
M

MGFoster

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Don't use OpenQuery; use a QueryDefs .Execute method instead. Example:

dim db as dao.database
dim qd as dao.querydef
set db = currentdb
set qd = db.querydefs("query name")
qd.Parameter!NewID = <double variable name>
qd.execute dbFailOnError

Since you're also using references to a form to pull other parameters,
why not put the NewID on the form? Then you'd not need to pass the
parameter to the query before executing. Here is how to set up the form
control's references as query parameters. E.g.:

PARAMETERS Forms![SINGLE BOOKING AVAILABILITY]!NewID IEEEDouble,
Forms![SINGLE BOOKING AVAILABILITY]!BookingDate Date,
Forms![SINGLE BOOKING AVAILABILITY]!Combo10 Integer,
Forms![SINGLE BOOKING AVAILABILITY]!Combo10 Integer;

UPDATE AVAILABILITY
SET AVAILABILITY.[Booking ID] = Forms![SINGLE BOOKING
AVAILABILITY]!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))

Be sure the PARAMETERS' data types correctly identify the data that will
be retrieved from your form(s).

Now you can run the OpenQuery (not recommended), or just execute the
query w/o explicitly assigning the parameters.

dim db as dao.database
dim qd as dao.querydef
set db = currentdb
set qd = db.querydefs("query name")
qd.Execute dbFailOnError

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQJ0IToechKqOuFEgEQLumgCgk9XvKSc1DB33cn518YtBr3gfgWwAoP4y
k8/9Fpmlek+LGGnWQiX1nnMh
=Zymw
-----END PGP SIGNATURE-----
 

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

Similar Threads


Top