Open "X" Form Depending On Selection

T

ThePro

I have a form wich has a drop down box and a command button wich now opens a
pre-determined form. What I want, if possible, is to open a specific form
depending on the option selected in the drop down box. This is the VB code
for the 'Open Form' command button.

Private Sub Enter_Click()
On Error GoTo Err_Enter_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Tabla-Estadisticas-Radiologo"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Enter_Click:
Exit Sub

Err_Enter_Click:
MsgBox Err.Description
Resume Exit_Enter_Click

End Sub

Thanks
 
D

Dirk Goldgar

ThePro said:
I have a form wich has a drop down box and a command button wich now
opens a pre-determined form. What I want, if possible, is to open a
specific form depending on the option selected in the drop down box.
This is the VB code for the 'Open Form' command button.

Private Sub Enter_Click()
On Error GoTo Err_Enter_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Tabla-Estadisticas-Radiologo"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Enter_Click:
Exit Sub

Err_Enter_Click:
MsgBox Err.Description
Resume Exit_Enter_Click

End Sub

Thanks

For example,

Select Case Me!MyComboBox
Case "A" : stDocName = "Tabla-Estadisticas-Radiologo"
Case "B" : stDocName = "SomeOtherTable"
Case "C" : stDocName = "YetAnotherTable"
Case Else
MsgBox "Please make a choice in the dropdown list."
Me!MyComboBox.SetFocus
Exit Sub
End Select

DoCmd.OpenForm stDocName, , , stLinkCriteria

It could be even simpler if you include the name of the form to be
opened as a hidden column of the combo box. Then you could just
reference that column:

If IsNull(Me!MyComboBox) Then
MsgBox "Please make a choice in the dropdown list."
Me!MyComboBox.SetFocus
Else
stDocName = Me!MyComboBox.Column(1) ' or 2, or 3 ...
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
 
T

ThePro

I get an 'Object Required' Message/Error.

Thanks

Private Sub Enter_Click()
On Error GoTo Err_Enter_Click

Dim stDocName As String
Dim stLinkCriteria As String

Select Case Me!NameOfEmployee
Case JohnDoe1: stDocName = JohnDoe1Form
Case JohnDoe2: stDocName = JohnDoe2Form
Case JohnDoe2: stDocName = JohnDoe3Form
Case Else
MsgBox "Please make a choice in the dropdown list."
Me!NameOfEmployee.SetFocus
Exit Sub
End Select
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Enter_Click:
Exit Sub

Err_Enter_Click:
MsgBox Err.Description
Resume Exit_Enter_Click

End Sub
 
D

Dirk Goldgar

ThePro said:
I get an 'Object Required' Message/Error.

Thanks

Private Sub Enter_Click()
On Error GoTo Err_Enter_Click

Dim stDocName As String
Dim stLinkCriteria As String

Select Case Me!NameOfEmployee
Case JohnDoe1: stDocName = JohnDoe1Form
Case JohnDoe2: stDocName = JohnDoe2Form
Case JohnDoe2: stDocName = JohnDoe3Form
Case Else
MsgBox "Please make a choice in the dropdown list."
Me!NameOfEmployee.SetFocus
Exit Sub
End Select
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Enter_Click:
Exit Sub

Err_Enter_Click:
MsgBox Err.Description
Resume Exit_Enter_Click

End Sub

You need quotes around the literal string values you're working with:

Select Case Me!NameOfEmployee
Case "JohnDoe1": stDocName = "JohnDoe1Form"
Case "JohnDoe2": stDocName = "JohnDoe2Form"
Case "JohnDoe2": stDocName = "JohnDoe3Form"
 
Top