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

Defining a form using Set or Let??

Status
Not open for further replies.

grobermatic

Technical User
Dec 21, 2002
153
GB
Hi,

I always get confused when it coms to referencing a form in VBA, I'm ok when referencing it directly (hard coding it) but I'm confused when using variables as forms??

========================================================

I'm using this simple code:

Dim strParentFormName As String

strParentFormName = Me.OpenArgs

Me.OpenArgs.Refresh

DoCmd.Close acForm, Me.Name

=========================================================
It doesn't work ?!?

I tried declaring the variable as a Form but then I get errors like "Object Required" and I sometimes get the message "Invalid Object Qualifier"

It would really help me with future projects if I didn't keep coming up against this problem.

Any advice would be much appreciated!!

Thanks


Craig
 
grobermatic,

The following code can used on a Form Class Module to reference the Form object.

Dim frm As Form
Set frm = Me
MsgBox frm.Name

If you need to reference it from a Global Module, then you would use:

Dim frm As Form
Set frm = Forms!myFormName
MsgBox frm.Name


Hope this assists

Logicalman
 
Thanks

So what if I wanted to reference a form indirectly, what I mean is that I dont want to hard-code the name of the form in to the code.

for example as above I have used the Me.OpenArgs property of the form. How would I refresh another form than the current one using OpenArgs?

the best I can comeup with is as above :

Dim strParentFormName As String

strParentFormName = Me.OpenArgs

Me.OpenArgs.Refresh

=============================================

But this doesn't work?!?!?!

Thanks again

Craig
 
grobermatic,

The following code demonstrates hwo to use form names as strings and assign them to a Form object.

Copy and paste it into a Global Module and run it:

Function SET_FORMNAME(ByVal sFrmName As String)
Dim frm As Form
Set frm = Forms(sFrmName)
Debug.Print frm.Name
End Function
Function test_SET_FORMNAME()
SET_FORMNAME "frmLists"
End Function

Logicalman
 
Me.OpenArgs - just string.
You can use expression Forms(Me.OpenAregs).Refresh , if your
Me.OpenArgs is valid form name.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top