0

I am curious to understand why the following throws and compile error stating it is expecting a function or variable

Dim frm as Form
set frm = DoCmd.OpenForm(FormName:=mstr_FORM_NAME, View:=acDesign, WindowMode:=acHidden)

but I can do this

DoCmd.OpenForm FormName:=mstr_FORM_NAME, View:=acDesign, WindowMode:=acHidden
set frm=Forms(mstr_FORM_NAME)

I have no issue with doing what works, I just want to understand what is going on with the former statement.

Thank you, Fred

2

2 Answers 2

2

DoCmd.OpenForm is a method which doesn't return a value. In the second code snippet you are accessing the Forms Collection, which contains the form, after it has been opened by DoCmd.OpenForm. When you call a method, you must not specify braces.

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

1 Comment

Well that makes perfect sense. I guess I just didn't understand well enough the idea of a method not returning a value. Thanks Peter.
2

The OpenForm method (doc) is not returning anything, just opening the form (not returning it).

So, you're trying to cast Nothing into a variable defined As Form. Instead, frm (having the Set frm = statement) is expecting to "become something", it is expecting a function or variable - a value, to be clear).

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.