I'm trying to provide a reference to a SubForm that is contained within a Main Form. Â The SubForm is not linked to the Main Form.
I have copied the Form Names directly from the Objects so they match exactly.
'Main Form Object Name: F-48-910 - Create New Event Import Data Form
'SubForm Object Name: F-48-911 - Create New Event Import Data SubForm
Code
Dim F48911_001 As Form
Set F48911_001 = [Forms]![F-48-910 - Create New Event Import Data Form]![F-48-911 - Create New Event Import Data SubForm].[Form]
When the 'Set' statement runs I get an Access Error Number 2465 Â 'Can't find the field 'F-48-911 - Create New Event Import Data Subform' referred to in your expression(2465).
I have tried for a couple of hours to fiugure this out without solving it.
Please help!
Thanks,
Bob C.
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
After the dot Intellisense will kick in and you have full access to all methods/properties/controls
if the form name has spaces in it then the reference is slightly modified
The key is, that after the main form name comes the name of the control hosting the sub form. Due to defaults of Access naming controls after content, it maybe named automatically with the same name of the sub form. But you need to check this in the property editor.
Thanks for the updates. Â I still can't get it to work having tried all kinds of syntax. Â i.e. Same error.
Having viewed the Properties - All Tab the Form Name is correct. Â However, please note that the Form Name is exactly as provided above including the spaces and special characters. Â This has always been my naming convention (I have it hundreds of Events where it works correctly) and the reason I use the 'Alias' method. Â e.g.:
Dim F48911_001 As Form
Set F48911_001 = [Forms]![F-48-910 - Create New Event Import Data Form]![F-48-911 - Create New Event Import Data SubForm].[Form]
I then use the Alias in referencing the Field. Â e.g. F48911_001!SORT_SEQ
Since F48911 is a form within F48910 I beleive the Set statement above is the correct one to use.
The string [F-48-911 - Create New Event Import Data SubForm] must be the name of the control in your form. Not the form name.
Attached is a sample using Main and Sub as form names:
Option Compare Database
Option Explicit
Private Sub txtReadValue_Click()
Dim SubForm As Access.Form
Set SubForm = Me!sfmSubForm.Form
Me.Caption = SubForm.txtValue.Value
Set SubForm = Nothing
End Sub
I finally found that the Form F48911 Name on the Property Sheet - Other Tab was still refereincing another form that I had used as a jump start to create this one. Â i.e. Related to Gustavs' comments.
Sorry for not identifying this earlier.
Thanks to all,
Bob C.
Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
I finally found that the Form F48911 Name on the Property Sheet - Other Tab was still refereincing another form that I had used as a jump start to create this one. Â i.e. Related to Gustavs' comments.
There is no reference on that tab. It's the name of the subform control.
Microsoft Access
--
Questions
--
Followers
Top Experts
Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.