VBA verbal as a criteria

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Can I set a verbal in VBA code that a query can the use as part of the
criteria for the query.

I am doing an update query on a set of data it runs find by its self. but
when a run it from code it can not read the combo box I have with the current
search criteria so. I would like to pass it a verbal with the information in
it instead of referencing a combo box on a from can this be done and who do I
do it.

Thanks
 
Hi Matt

In your VBA code create a function like the following one. VariableName is
your VBA variable.

Function FunctionName()
FunctionName = VariableName
End Function

In design mode of your query, right mouse click in the criteria box you wish
to use your function variable in. Select 'Build' option in the popup. Click
on 'Functions' to expand the list of functions. Select the VBA module your
function resides in. Your function should be listed in the right most
column. Double click it and OK. Bubda bing budda boom, your variable is the
criteria for your query.

For kicks click on the SQL view mode for your query (instead of Design View)
to see what the SQL code looks like.

Hope this helps
Norm
 
WOW...

This is something I have been looking for. Thanks Norm.

I set up function in a module for my database

Function testjbl()
testjbl = variablename
End Function

I have a button on a form that on click
variablename=7

In a query I set criteria to testjbl()

when I run it ...Function not recognized...

Any help??? Does it matter where the function code is or how to set the
value for variablename??

Thanks, Joel
 
The function should be public and in a standard module (NOT behind a FORM, a
CLASS, a REPORT).


Vanderghast, Access MVP
 
Back
Top