AStopher
AStopher

Reputation: 4561

Access cannot find the referenced form

I am in the final stages of testing a small piece of software I made, and am experiencing a Access cannot find the referenced form 'Customer Picker':

enter image description here

I've checked over my syntax for accessing the form, and there's nothing wrong with it. I've also looked for a solution to this (this issue being well documented on Stack Overflow) but nothing has worked.

This is the (partial) code I'm using:

DoCmd.OpenReport "Invoice", acViewPreview
If (Forms![Customer Picker]![Combo3].Value = "Business") Then
    Reports![Invoice]![Text154] = Forms![Customer Picker]![Text8]
Else
    Reports![Invoice]![Text154] = Forms![Customer Picker]![Text10] + " " + Forms![Customer Picker]![Text6]
End If

My objective is to populate a report based on the information entered in the form, and then print the report (haven't got as far as that yet).

What am I doing wrong here, and how can I fix this?

Upvotes: 4

Views: 21172

Answers (2)

user23064019
user23064019

Reputation: 1

Supplementing the other answer: if you want to set a reference to a form or subform as a whole, you need to specify ".Form" after the form's name - e.g.,

Dim myForm as Form

Set myForm = Forms("FormName").Form

If you omit the ".Form". Access will throw a runtime "type mismatch" error.+

Upvotes: 0

HansUp
HansUp

Reputation: 97131

You can only reference Forms![Customer Picker] when the form is open. But you reported that CurrentProject.AllForms("Customer Picker").IsLoaded returned False.

If it is included as a subform in some other form which is open, you can reference it via the name of the subform control on that other form:

Forms![Other Form]![Subform Control]![Text8]

Note that the name of the subform control may not be the same as the name of the form which it contains.

Upvotes: 14

Related Questions