Changing underlying table/query in a form

  • Thread starter Thread starter AccessRookie
  • Start date Start date
A

AccessRookie

Hi All,
Once a form has been created with a table or a query, is there any way
to change which table/query the form is used for? I made a form based
on a table, but now want to use that same form on another table.

Thanks!
 
Hi,
You can use the form with other tables/queries. If you
aren't adept at programming visual basic, you will want
to simply make a copy of the form object and change
the "Recordsource" property in the new form.
To change the recordsource property, you must open the
form in design view (right click on the form and
select "Design View" from the list). When in design view,
select View->Properties from the menu. In the dialog,
select the "Data" tab and find the "Record Source" entry.
You can select or type the table or query. You may also
build a query by clicking on the "..." button to the
right.
 
AccessRookie said:
Once a form has been created with a table or a query, is there any way
to change which table/query the form is used for? I made a form based
on a table, but now want to use that same form on another table.


Sure, you can modify the form's RecordSource property using
VBA code in the form. You did not explain how you will
determine which query is supposed to be used, but you could
use code in the form's Open event:

If <somecondition> Then
Me.RecordSource = "query1"
Else
Me.RecordSource = "query1"
End If

OTOH, if some other form want to open this form using a
specific query, it could use the OpenForm method's OpenArgs
argument to tell the form which query to use:

DoCmd.OpenForm "theform", OpenArgs:="query2"

and the code in the form's Open event:

If Not IsNull(Me.OpenArgs) Then
Me.RecordSource = Me.OpenArgs
End If
 
Hi All,
Once a form has been created with a table or a query, is there any way
to change which table/query the form is used for? I made a form based
on a table, but now want to use that same form on another table.

Thanks!

Just open the Form in design view; view its Properties; and change the
Recordsource property to the desired table.
 
Back
Top