问题
When I click on the Create New Form button below, I get the following runtime error 2450 dialog box:

When I click on the debug button, it gives me the following:

The main form is called FindClientsNavigation. The "Create New Form" button in the ListOfForms subform is supposed to cause the NavigationSubForm to replace the ListOfForms form with a new CommunicationForm so that the user can enter information from a new form for the Client with the specific Client ID that is available in the txtClientID textbox, which you can see in the top of the FindClientsNavigation form in my first image above.
How do I alter the code above so that it loads a new CommunicationForm in the NavigationSubForm? And how do I get that new CommunicationForm to have the ClientID stored in it, so that submitting the form will allow the form to be saved with reference to the specific ClientID?
回答1:
The SourceObject needs to be set to a string, which is the name of the form to use:
.SourceObject = "CommunicationForm"
[Note that Forms
is the collection of open forms so you cannot use this to refer to a form in the Navigation Pane - unless you know that this form is open.]
You can use the Client ID (on the main form) for this subform, but there are a number of ways to do this and it depends on your specific requirement:
- The subform could be based on a query that refers to the textbox (perhaps
txtClientID
) on the main form. This is one of the simpler approaches. - You could dynamically set the
RecordSource
for the subform, using a WHERE clause that refers to the Client ID (similar to the above approach). - You could apply a
Filter
to the subform, so that it only displays the single record for the Client ID.
来源:https://stackoverflow.com/questions/18903606/cannot-find-the-referenced-form