1

It seems so simple, but I can't seem to find the correct syntax. I am looking to create a form variable for an unopened form in my Access 2013 application so I can pass the form object to a series of methods rather than passing separate properties of the form.

Here's what I've been attempting, but I run into Run-time error '2465' "Microsoft Access can't find the field 'frmSuppliers' referenced in your expression.

Private Sub cmdSuppliers_Click()
    Dim frm As Form
    Set frm = Form("frmSuppliers")

    Debug.Print frm.Name
1
  • You have to open the form for it to be initialized and added to the forms collection of the DB Commented Jan 11, 2017 at 21:29

2 Answers 2

5
Private Sub cmdSuppliers_Click()
    Dim frm As Form
    Set frm = Forms("frmSuppliers")

    Debug.Print frm.Name

You referenced the Forms collection but made it singular instead of plural.

Sign up to request clarification or add additional context in comments.

Comments

3

Thank you Sorceri and Christopher. I seem to have been missing a compilation of the wrong reference to the forms collection and not opening the form prior to setting the variable. This code seems to do the trick:

Private Sub cmdSuppliers_Click()
    Dim frm As Form

    DoCmd.OpenForm "frmSuppliers", acNormal, , , , acHidden
    Set frm = Forms("frmSuppliers")

    Debug.Print frm.Name

    DoCmd.Close acForm, frm.Name
    Set frm = Nothing

End Sub

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.