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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trick to VBA Syntax for Forms

Status
Not open for further replies.

davidmo

Technical User
Apr 8, 2003
97
US
Hey Everyone:
I am having trouble calling up forms through VB and am not sure if it is my syntax or the way I name my forms in Access.

I begin every form name as "frm_" and then add a logical name pertaining to the form. Not sure if this causes a problem for VB.

As an example I have a table called frm_Current_Employment

I type it in VB like this: Form!frm_Current_employment!

Just interested in people's thoughts.

Thanks.

DMo
 
DMo
It depends upon what you are trying to do with the form.

For example, if you are trying to open that form from a command button on your main menu...
DoCmd.OpenForm "frm_Current_Employment"

In other instances, such as trying to reference a control on the form, you might have to put square brackets around the name, i.e. [frm_Current_Employment]

Tom
 
Tom:
Thanks for the info.

What if the form you are trying to call is a subform?

DMo
 
David
The thing to keep in mind here is that a subform is a control on a form, and needs to be referenced as such.

In VBA take a look in Help for subforms.

Here are lines that I just took out of that Help...
The next two examples show how you might refer to a control named NewData on a subform ctlSubForm contained in the form called OrderForm:

Forms!OrderForm.ctlSubForm.Form!Controls.NewData
Forms!OrderForm.ctlSubForm!NewData


In your particular case, if the name of the subform was frm_Current_Employment, then it would go something like
Forms!MainFormName.[frm_Current_Employment].Form!WhateverField

You might not need the square brackets. You can try it without, and if it doesn't work put it in.

Hope that helps.

Tom
 
The underscore is a perfectly legal character. No need for brackets. The standard is just three characters

frmYourFormName
tblYourTableName
qryYourQueryName

Googl Reddic, Hungarian, and VB Naming conventions.

The only thing wierd with that. Is the form class gets "Form_" appended to all form objects.
So in code you may see something like in your case

dim myForm as New Form_frm_Current_Employment

Looks a little wierd, but no problem.
 
A subform is a form. What do you mean by "call a subform"? To reference a control on a subform from the main form you use:
Forms!frmMain!subFormName.Form!controlOnSubForm
where the words Forms and Form remain unchanged.
 
How are ya davidmo . . .

Remember you are the programmer of this DB and one of the best things you can do for yourself is heighten its [blue]readability[/blue] . . . for you!

Keep your naming convention short (character count) and pack words if necessary. Just looking at it . . . would'nt you say:

[blue]frmCurEmploy[/blue]
is more readable at first sight than
[blue]frm_Current_employment[/blue]

[purple] . . . espcially if it appears anywhere say 20 times or more?[/purple]

Drop the underscore, keep it short, and get on with it!

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top