Hi Dean,
What you ask is exactly the way I work with all my Access-applications.
In the way I can tune the next form exactly depending on the values of
the former forms.
In the Form_open-procedure you make your SQL-string.
Such a string looks like: cur_sql = "SELECT " & cur_fields & " FROM " &
cur_tables & cur_criteria & cur_order.
e.g.
cur_fields = "*,Concat(First _name,Middle_na me,Last_name) AS Person"
cur_tables = "(Person_tb l INNER JOIN Member_tbl ON Person_tbl.Pers on_id
= Member_tbl.Pers on_tbl)"
cur_criteria = " WHERE First_name = " & As_text ("Jan")
cur_order = " ORDER BY Last_name"
Concat is an own_made string-function which adds a space and a value if
this value <Null, for each parameter.
As_text is an own_made string-function that returns the quoted
parameter (you don't have to bother about the right number of quotes).
Finally, if you are happy with your cur_sql, assign it to the forms'
Recordsource:
Me.RecordSource = cur_sql.
In fact I build a systematic, in which this cur_sql is generated
automatically, appliclable for any database.
Success, HBinc.
DeanL wrote:
Hi All,
How do you run a SELECT query from code? I know that DoCmd.RunSQL only
works with action or DDF queries but I need to run a query from VBA and
add variables into the query as defined by entries on a form.
Many thank, Dean...