Opening another form from a combobox selection

  • Thread starter Thread starter Lorraine
  • Start date Start date
L

Lorraine

Thanks for the help but it is still not working. I have
also created OpenForm macros and have tried to put
the following code in the LostFocus event of the combobox
but this did not work either:

Am I missing a step? Does Access look at my options table
to descide which case to run? Maybe my code is not linking
to the options table. How do I link that?


Private Sub cmbID_tag_LostFocus()
Select Case Me!cmbID_tag
Case 1
DoCmd.RunMacro (OpenN_switches_Entry_Form)
Case 2
DoCmd.RunMacro (OpenID_tags_other_Entry_Form)
Case 3
DoCmd.RunMacro (Openprinters_Entry_Form)
Case 4
DoCmd.RunMacro (OpenS_Entry_Form)
Case 5
DoCmd.RunMacro (OpenC_Entry_Form)
End Select
End Sub
-----Original Message-----
Your options should be in a table that looks like this:
TblOption
OptionID
Option

and OptionID should be 1 to 5.

You can then put the following code in the AfterUpdate event of the combobox:

Select Case Me!NameOfCombobox
Case 1
DoCmd.OpenForm "DataEntryForm1"
Case 2
DoCmd.OpenForm "DataEntryForm2"
Case 3
DoCmd.OpenForm "DataEntryForm3"
Case 4
DoCmd.OpenForm "DataEntryForm4"
Case 5
DoCmd.OpenForm "DataEntryForm5"
End Select


--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
(e-mail address removed)
www.pcdatasheet.com





.
..
 
Hi Lorraine

First, please don't post a new message to ask for follow-up help. Instead,
post a reply to the message in the original thread. That way it can be
understood in context and it is much more likely to be seen by the person
who helped you originally.

Second, the LostFocus event is probably not the best event to use here, as
it will fire if the user just tabs into the control and out again without
making a selection. If you want the selected form to open the moment a
selection is made, then use AfterUpdate. Or, if you want the user to make a
selection and then have a positive action to open the form, then add a "Go"
command button next to the combo box and use its Click event.

Third, what is the RowSource of your combo box? Is it based on a table? If
so, does the bound column of the combo contain the numeric values 1 to 5?
If not, then no part of your case statement will be satisfied and your
procedure will do nothing.

Fourth, is OpenN_switches_Entry_Form the name of a macro, or the name of a
variable? I suspect it is a macro, but it will be read as a variable which
I guess does not exist and will therefore be implicitly declared as Null.
You should put it in quotes so that VBA interprets it as a string constant,
not a variable. Also, *every* code module you ever write should *always*
have Option Explicit as the first line, so that variables cannot declare
themselves.

Fifth, why call a macro to simply open a form? If the macro
"OpenN_switches_Entry_Form" opens the form called "N_switches_Entry_Form"
then ditch the macro and open the form directly:
DoCmd.OpenForm "N_switches_Entry_Form"

I suggest you set up a table tblFormList with two fields: FormName and
FormDescription . Add one record for each of your forms - for example:
FormName: N_switches_Entry_Form
FormDescription: Switches data entry

Use this table as the RowSource of your ComboBox. Set the following other
properties:
Columns: 2
BoundColumn: 1
ColumnWidths: 0 (this hides the first column)

Now, the value of the combobox is the actual *name* of the form you wish to
open, so your code needs only one line:
DoCmd.OpenForm Me!cmbID_tag

Put this in the AfterUpdate procedure or an button Click procedure as
required.
 
You were right on the money. Thank you so very much. I
will take ALL the advice given!
-----Original Message-----
Hi Lorraine

First, please don't post a new message to ask for follow- up help. Instead,
post a reply to the message in the original thread. That way it can be
understood in context and it is much more likely to be seen by the person
who helped you originally.

Second, the LostFocus event is probably not the best event to use here, as
it will fire if the user just tabs into the control and out again without
making a selection. If you want the selected form to open the moment a
selection is made, then use AfterUpdate. Or, if you want the user to make a
selection and then have a positive action to open the form, then add a "Go"
command button next to the combo box and use its Click event.

Third, what is the RowSource of your combo box? Is it based on a table? If
so, does the bound column of the combo contain the numeric values 1 to 5?
If not, then no part of your case statement will be satisfied and your
procedure will do nothing.

Fourth, is OpenN_switches_Entry_Form the name of a macro, or the name of a
variable? I suspect it is a macro, but it will be read as a variable which
I guess does not exist and will therefore be implicitly declared as Null.
You should put it in quotes so that VBA interprets it as a string constant,
not a variable. Also, *every* code module you ever write should *always*
have Option Explicit as the first line, so that variables cannot declare
themselves.

Fifth, why call a macro to simply open a form? If the macro
"OpenN_switches_Entry_Form" opens the form called "N_switches_Entry_Form"
then ditch the macro and open the form directly:
DoCmd.OpenForm "N_switches_Entry_Form"

I suggest you set up a table tblFormList with two fields: FormName and
FormDescription . Add one record for each of your forms - for example:
FormName: N_switches_Entry_Form
FormDescription: Switches data entry

Use this table as the RowSource of your ComboBox. Set the following other
properties:
Columns: 2
BoundColumn: 1
ColumnWidths: 0 (this hides the first column)

Now, the value of the combobox is the actual *name* of the form you wish to
open, so your code needs only one line:
DoCmd.OpenForm Me!cmbID_tag

Put this in the AfterUpdate procedure or an button Click procedure as
required.
--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

Thanks for the help but it is still not working. I have
also created OpenForm macros and have tried to put
the following code in the LostFocus event of the combobox
but this did not work either:

Am I missing a step? Does Access look at my options table
to descide which case to run? Maybe my code is not linking
to the options table. How do I link that?


Private Sub cmbID_tag_LostFocus()
Select Case Me!cmbID_tag
Case 1
DoCmd.RunMacro (OpenN_switches_Entry_Form)
Case 2
DoCmd.RunMacro (OpenID_tags_other_Entry_Form)
Case 3
DoCmd.RunMacro (Openprinters_Entry_Form)
Case 4
DoCmd.RunMacro (OpenS_Entry_Form)
Case 5
DoCmd.RunMacro (OpenC_Entry_Form)
End Select
End Sub
.


.
 
Back
Top