Hi,
I have an access form where record source is a query. I like to know if there is a way, we can use if statement to choose between 2 different query say query1 and query 2 to be used on the record source.
I have another form say Form1 and a click button event which will launch this form From2.
Based on an entry on a text field on Form1, i want to launch Form2 either using one of the query on the record source.
I don't want to replicate the Form2 which uses query1 and do it as Form3 with query2 and based on condition on Form1 launch Form 2 or 3, reason this form is complex and I have multiple forms so I have to do this for all. Rather if I can control which query to use from record source will be awesome.
Wondering if there is an option.
Yes, that's very doable in many ways. Two simpler methods:
1. Modify the SQL of the query object in form 1 before you open form 2. Form 2 always points to the same query object and requires no additional code.
Or
2. Use the OpenArgs argument to pass a flag to form 2 on what it should use. In its OnOpen event, it would set its recordsource based on that flag.
The recordsource could be set to either two different queries, or with two different SQL statements directly.
Jim.