0
votes

I have a single form which can be accessed from multiple places in my Access 2013 app - depending on where the form is opened from, the recordsource should be different - for example if opening the form to search for a record, the form recordsource is a parameter query where the user enters the record id as the parameter - but if opening the form from elsewhere the recordsource is a select query and the record id is passed using VBA.

I want to avoid having twin forms if possible - I just want a single form and be able to set the recordsource when the form opens... is it possible to set the form recordsource upon opening the form (rather than after the form is opened)?

1

1 Answers

1
votes

Have a bit of VBA that rewrites the query that your form reads from. Try this:

Set db = CurrentDb()
DoCmd.DeleteObject acQuery, "myFormQuery"
Set q = db.CreateQueryDef("myFormQuery")


q.Sql = "SELECT * FROM mytable WHERE 1=1;"
DoCmd.OpenForm "myForm", acNormal