Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Really can't find how to do this....

Status
Not open for further replies.

stickers

Technical User
Nov 25, 2002
82
GB
Hi all,

I have looked everywhere and cannot find out how to do this or whether it is possible. In my database I have a parameter query which is used in several other queries. When I open one of the others (usually with a button on a form), I want VB to automatically put in the parameter, so that the user doesn't see the parameter request. The user would never open the parameter query - just the ones that bounce off it.
Does anyone know a way of doing this????

Stickers
 
Here's how you execute a parameter query via code. Is this what you're looking for? Note that in the example below, dteBegin and dteEnd are fields on a from from which the user can enter a date range.

Dim dbs As DAO.Database
Dim qdf As DAO.QueryDef
Dim rst As DAO.Recordset

Set qdf = dbs.QueryDefs("YourParameterQuery")
qdf.Parameters("Enter Begin Date") = dteBegin
qdf.Parameters("Enter End Date") = dteEnd
Set rstI = qdf.OpenRecordset()
 
How about using a variable criteria similar to:
[Enter the parameter that is being requested]
Or [Forms]![frmName]![txtParameter] If there is anything in the Parameter textbox it will use it otherwise it will use the input Parameter
 
Thanks for the replies both! It's not over though.....

Firstly, I've used ADO through the rest of my database. Can I switch to DAO and if not, what would be the equivalent code? I can't find any query-type objects in ADO at all - although I know how to open a recordset using SQL which is sort of the same thing (?)

Secondly - I'm not sure how well I explained the prob.:

Query A is the query which needs the parameter.
Query B uses query A (plus some other things)
Query C uses query B (plus some other things)
Form C has Query C as its record source.

The value for the parameter is in Table D (not directly related to any of the queries - but I could pull it out using recordsets.)

What I want to happen is when the user opens Form C a message box comes up saying "Do you want to adjust the costs?" If no, then the parameter value is 1, and if yes, then the parameter value is the value from the table (found using a recordset).

I've figured out a work around, by putting an invisible text box in the form from which you open Form C, but it would be nice to be able to say in code "Open this form and when you get to this query, use X as the parameter"

Any ideas? Not so urgent now, because the work around works, but I'm still curious.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top