Change commands under program control

G

Guest

Is there a way to have commands changed under program control? In my menue,
I use the following code to check if a Form is already open and, if so make
it visible or if not. Open it.
Forms.mnu_menu.Visible = False
If CurrentProject.AllForms("frm_Stock").IsLoaded = True Then
Forms.frm_Stock.Visible = True
Else
DoCmd.OpenForm "frm_Stock", acNormal, "", "", , acNormal, MenuSelect
End If
I would like to pass the form name to a sub as a string and that way I could
use one piece of code instead of cnstantly duplicating it.

Should be something like DoCmd.openForm.[string containing form name].Visible

Thanks for any help RayC
 
J

John Spencer

You are already working with strings for two of the three. Just use the
alternate syntax of Forms(StrFormName).

Sub sOpenForm(strFormName as string)

If CurrentProject.AllForms(strFormName).IsLoaded = True Then
Forms(strFormName).Visible = True
Else
DoCmd.OpenForm strFormName, acNormal, "", "", , acNormal, MenuSelect
End If


You can refer to forms and reports and controls with alternative syntax

Forms(StrFormName).Controls(strControlname).Visible = True



'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================
 
G

Guest

Of Course !! Having a "Dumb" Day.

Thanks RayC

John Spencer said:
You are already working with strings for two of the three. Just use the
alternate syntax of Forms(StrFormName).

Sub sOpenForm(strFormName as string)

If CurrentProject.AllForms(strFormName).IsLoaded = True Then
Forms(strFormName).Visible = True
Else
DoCmd.OpenForm strFormName, acNormal, "", "", , acNormal, MenuSelect
End If


You can refer to forms and reports and controls with alternative syntax

Forms(StrFormName).Controls(strControlname).Visible = True



'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================


Ray said:
Is there a way to have commands changed under program control? In my menue,
I use the following code to check if a Form is already open and, if so make
it visible or if not. Open it.
Forms.mnu_menu.Visible = False
If CurrentProject.AllForms("frm_Stock").IsLoaded = True Then
Forms.frm_Stock.Visible = True
Else
DoCmd.OpenForm "frm_Stock", acNormal, "", "", , acNormal, MenuSelect
End If
I would like to pass the form name to a sub as a string and that way I could
use one piece of code instead of cnstantly duplicating it.

Should be something like DoCmd.openForm.[string containing form name].Visible

Thanks for any help RayC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top