Open different form based on combo box selection

R

Ruth

I have a "details" button on a continuous form that, when clicked, I
want it to open a specific form based on a value in a combo box. The
continuous form is a subform, which I think may be causing the
problem.

This is the code on the button. It doesn't generate an error, but it
doesn't do anything either. The parent form is frmCell and the subform
is frmCellTasks

Ideas?
Private Sub btnDetails_Click()
On Error GoTo Err_btnDetails_Click

Dim stDocName As String
Dim stLinkCriteria As String

If Me.Task = "Inspection" Then

stDocName = "subInspItem"

stLinkCriteria = "[TaskID]=" & Me![TaskID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

If Me.Task = "Jig Test" Then

stDocName = "subJigMove"

stLinkCriteria = "[TaskID]=" & Me![TaskID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

If Me.Task = "Leak" Then

stDocName = "subLeakItem"

stLinkCriteria = "[TaskID]=" & Me![TaskID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Else: MsgBox "This task does not have details.", vbOKOnly
End If
End If
End If


Exit_btnDetails_Click:
Exit Sub


Thanks!


Err_btnDetails_Click:
MsgBox Err.Description
Resume Exit_btnDetails_Click

End Sub
 
D

Douglas J. Steele

Your If statements are set up such that if Me.Task isn't "Inspection", none
of the other statements are executed.

Try

Private Sub btnDetails_Click()
On Error GoTo Err_btnDetails_Click

Dim stDocName As String
Dim stLinkCriteria As String

Select Case Me.Task
Case "Inspection"
stDocName = "subInspItem"

Case "Jig Test"
stDocName = "subJigMove"

Case "Leak"
stDocName = "subLeakItem"

Case Else
stDocName = vbNullString

End Select

If Len(stDocName) > 0 Then
stLinkCriteria = "[TaskID]=" & Me![TaskID]
DoCmd.OpenForm stDocName, , , stLinkCriteria
Else
MsgBox "This task does not have details.", vbOKOnly
End If

Exit_btnDetails_Click:
Exit Sub

Err_btnDetails_Click:
MsgBox Err.Description
Resume Exit_btnDetails_Click

End Sub
 

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