Using variables in form record source sql statements

  • Thread starter Thread starter kclark
  • Start date Start date
K

kclark

Guest
Trying to find out how to imbbed a variable into the sql code for a forms record source property. Anyone help?
 
to get the hang of SQL, you can build a query that performs the action you want to perform...then click View/SQL View. This will give you the syntax in SQL. You can copy and paste this into your record source of your form.

Alternatively, when you are in design mode of your form, in the Record Source property, select the query builder. This will bring you to a design grid where you can place the fields you want. Then, instead of saving, just exit the grid...Access will ask you if you want to save the changes to the SQL statement. Say "yes" and the appropriate syntax will show up in your record source.

Good luck!
 
VBA variable into SQL?

If I understand the question correctly, you want to put a VBA variable into your SQL. The answer is a bit trickier than you'd expect, since they're two different 'languages'.

Build a function whose SOLE purpose is to return the value of that variable. Then you can reference that function in your custom-built SQL.

If I'm misunderstanding, can you give a more concrete example of what you're trying to do?

I.e. "I want my form to come up for all records with Cost Benefit Analysis values greater than 4.5"
 
If kclark wasn´t wondering how to put a VBA variable into sql, I certainly am.

I am trying to build a statistics form that should run several queries and returning values to controls on the form, depending on what the user puts in some other controls.

For instance, the user might be interested in the statistics for mondays, which means the sql query needs a variable in the where-clause.

Or am I wrong about this?

Fuga.
 
Well, you could select just Mondays with a combo box, a listbox, or a parameter in the query. VBA variables would be needed when the question isn't so simple, and might rely on some calculations being done to the user input first.
 

Users who are viewing this thread

Back
Top Bottom