Avatar of peispud
peispud
Flag for Canada asked on

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

Microsoft Access

Avatar of undefined
Last Comment
Gustav Brock

8/22/2022 - Mon
Kyle Abrahams, PMP

Dim TheForm as Form = Forms(FormName)
peispud

ASKER
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

SOLUTION
Rey Obrero (Capricorn1)

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Gustav Brock

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
peispud

ASKER
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.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Rey Obrero (Capricorn1)

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
ASKER CERTIFIED SOLUTION
Gustav Brock

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.