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

peispudAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook 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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.