• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 140
  • Last Modified:

Refering to a form using a variable.

Hi
 
See the code below.  I want to enter into the sub with the name of the form as a string.  I will need to refer to that form directly later.   I wish to do this by using syntax similar to  what the code below.

I would appreciate help in fixing that code.

Thanks


Public Sub CheckDuplicates(ByVal FormName As String, ByRef lblCommunicate As Label)
    Dim TheForm As Form: Set TheForm = Forms(FormName)

Open in new window

0
peispud
Asked:
peispud
  • 2
  • 2
  • 2
  • +1
3 Solutions
 
Kyle AbrahamsSenior .Net DeveloperCommented:
Dim TheForm as Form = Forms(FormName)
0
 
peispudAuthor Commented:
Thanks for your reply, but it did not work.   The syntax failed.

I used the  following  but  got "Invalid use of property"....  

Public
 Sub CheckDuplicates(ByVal Const_FormTable As String, ByRef lblCommunicate As Label)
Dim TheForm As Form:  TheForm = Forms(Const_FormTable)

Open in new window

0
 
Rey Obrero (Capricorn1)Commented:
try

Dim TheForm As Form: Set  TheForm = Forms(Const_FormTable)
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Gustav BrockCIOCommented:
First, your form must be open to do this.
Second, if so, you could simply do:

Public Sub CheckDuplicates(ByRef TheForm As Form, ByRef lblCommunicate As Label)
    Debug.Print TheForm.Name
    ' Other stuff.
End Sub
/gustav
0
 
peispudAuthor Commented:
Thank you for your replies, but I have not found resolution to my original question.
I have re-read it.  I believe that I have phrased the question correctly.

I am using Microsoft Access 2013.
0
 
Rey Obrero (Capricorn1)Commented:
are you getting an error? what is the error?

the form must be open, and this should work

Dim TheForm As Form: Set  TheForm = Forms(Const_FormTable)

debug.print TheForm.Recordsource
0
 
Gustav BrockCIOCommented:
>   I believe that I have phrased the question correctly.

Yes, and you've got the answer.

/gustav
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now