Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling Forms with spaces Using the Form_ method in VBA

Status
Not open for further replies.

dmaranan

Programmer
Aug 14, 2001
46
US
Hello!

How do I use the form_ method when a form has spaces.

Form exmample, I'm writing a code that sets data to a form object. The form's name is Application Entry, and the data is first name.

Using the Forms! method this is accomplished by the following syntax Forms![Application Entry].firstname = Fred.

But I need to use the Form_ method. Does anyone know the syntax? Form_Application Entry.firstname = Fred, does not work.
 
It looks to me like you're confusing VBA's naming convention for an object's events (i.e. Form_Open) with the syntax for referring to a form object. Your first example is a valid way of referring to a form object (if it's currently open); FWIW, I prefer the bang vs. the dot for referring to controls on a form, though. Here's another way:

Code:
Forms("Application Entry")!firstname = "Fred"

Note that I have enclosed "Fred" in quotes, so Access knows it's a string; otherwise Access will interpret Fred as the name of a variable. If you have Option Explicit specified in your declarations, this will cause an error when the code compiles. If not, the code will compile and run, it just won't work.

If the form is closed, you can refer to it using a reference to the AllForms collection, i.e.:

Code:
Application.CurrentProject.AllForms("Application Entry")

However, you can't write data to a control on a form that's closed, so that reference is probably irrelevant for the purpose of your question.

Why is it that you think you can't use the syntax of your first example?

Ken S.
 
Does this do what you need?
[Form_Application Entry].firstname = Fred
HTH
JSouth
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top