Using a variable form name


Dim GenericForm as string
GenericForm ="FrmMain"
DoCmd.OpenForm GenericForm, , , stLinkCriteria


The syntax of the last line above is wrong and the "GenericForm" causes a crash!
FrmMain is a valid form name.

What should I do to the final statement to make it work

Patrick O'DeaAsked:
Who is Participating?
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.

DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Use just this:
DoCmd.OpenForm GenericForm
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Otherwise, (example only) ... it might be something like this, if you need a WHERE clause so the other form opens to a specific record:


Dim GenericForm As String
Dim stLinkCriteria As String
stLinkCriteria = "[CompanyID = " & Me.txtCompanyID
GenericForm = "FrmMain"
DoCmd.OpenForm GenericForm, , , stLinkCriteria

mx
0
Patrick O'DeaAuthor Commented:
mx,

Almost there with this one .... but I would like to change to question slightly.

Take line below.
(GenericForm = FormA)

DoCmd.OpenForm GenericForm, , , stLinkCriteria

However, this is not quite what I want.
FormA is NOT a form - It is a value from table tblControls

So I do NOT want to open a form called FormA.
I DO want to open a form that contains the value held in tblControls.FormA

Thanks,


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.

DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
ok ... how are you grabbing the value of tblControls.FormA ?
Maybe DLookup() ?

Something like:

Dim GenericForm as String
GenericForm =DLookup("[FormA]","tblControls")

DoCmd.OpenForm GenericForm

Guess I'm not clear on how you are getting the value of tblControls.FormA ?

mx
0
Patrick O'DeaAuthor Commented:
I am trying to give the user a facility to define their own "menus".
It is a slighty tricky concept so I won't go into detail.
Suffice to say that the process I am using results in some curious requirements.

The value of tblControls.FormA is shown on the current form.

tblControls.FormA has a value of "frmSuppliers"

Therefore frmSuppliers is the name of the form I wish to open - obviously not hardcoded.

So, DoCmd ....???

Hopefully this is clear - although I appreciate it is a little tricky!
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
"The value of tblControls.FormA is shown on the current form."
ok ... where?  You mean in a text box? or ?  IE, I see what you are trying to do ... just trying to figure out exactly where/how to grab the value in tblControls.FormA
Or are you saying that tblControls is the RecordSource for this form?

If so, then maybe

DoCmd.OpenForm Me![FormA]   ' get frmSuppliers from FormA field from tblControls ... ?

mx

0
Patrick O'DeaAuthor Commented:
Thanks for persevering ,

See attached - This may or may not make sense! No need to dig too deep.
Perhaps have a look at table MenuOptions. (No need to do this tho).

Run form TestMenu.
Click on "Create/Modify Suppliers Now"
The system will stop.

You can ignore the msgbox.  
In the immediate window (see below) you can see the values I refer to.
(Note I want to open the form frmSuppliers)

?genericform
Option1Form
?option1form
frmSuppliers

Database14.accdb
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
ok ... standby ... activating my A2010 system  ...

mx
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Ok ... here you go.
See the new code for Option 1 (and 2). Repeat for other options.  You just need one line of generic code ... same for all options.

NOTE**:  Since you did not include the other tables for the other forms, I had to remove the RecordSource on those forms (1 & 2) so they would open w/o error.

mx
Database14-MX01.zip
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
Patrick O'DeaAuthor Commented:
That's it.

I knew it would be easy (in the end).

Thanks once again for you perserverance on this one!



... if you have any interest in golf perhaps you are watching my fellow Irishman leading the charge in the US Masters!!
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
You are certainly welcome ...

mx
0
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.

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.