Link to home
Start Free TrialLog in
Avatar of peispud
peispudFlag 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

Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

Dim TheForm as Form = Forms(FormName)
Avatar of 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
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 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.
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
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial