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

passing a form name as a variable

Status
Not open for further replies.

striker73

MIS
Jun 7, 2001
376
US
I am trying to make a global function that will let me know if specific text boxes are filled out in the form. I originally write the function on the form I was working on and so I was using syntax like:

Me.Controls(TextBoxName).text

However, when I put the function in a code module, the function can't deal with the whole "Me.something" syntax. I am trying to pass in the form name, but I get the error "Invalid qualifier" when I use the syntax: FormName + dot + something. This is because "FormName" is a string and not referring to the actual form itself.

I know I can use the following syntax and I'm wondering if there is anything like it that will help me out. Any ideas? Thanks!

frmMyForm.Controls(stringname).Text
 
Well, I just remembered that I can use Forms!FormName of Forms![FormName], however it doesn't seem to be working. It says that it can't find the form named "FormName" because that is the name of my string, not the value inside the string. Any ideas? Thanks!
 
If you want to pass a form to a function you should be able to do it by creating a form object.

Dim yy As Form
Set yy = Forms!frm_IDTable.Form
DealWithForms(yy)

Public function DealWithForms(xx as Form)
Should be able to reference the form with xx
xx.recordset
xx.fields
xx.Controls.Item
etc....
End function
 
Cmmrfrds is perfectly correct. There's also another way - use the Screen.ActiveForm object. I like this way because you don't have to pass the value - it automatically knows just by checking the active form. I also use Screen.ActiveControl a lot.

Public Function DealWithForms(whatever..)
Dim frm as form
Set frm = Screen.ActiveForm
etc etc etc
End Function


Ex-JimAtTheFAA
78.5% of all statistics are made up on the spot.
Another free Access forum:
More Neat Access stuff at
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top