Incorrect reports opening

A

Anthony

Hi

I have a form called "PostOpInstructions" which has on it a command button
that is supposed to open one of several different reports when pressed. The
code for this command button is shown below. The report that opens depends
on the value contained within a field (actually a combo box) called
"OperationType1", which is located on another form called "Operation". The
user enters data in the "Operation" form, then clicks on a command button to
open the "PostOpInstructions" form, in which more data is entered.

The problem is that the wrong report opens when I click the command button
on the "PostOpInstructions" form. The problem seems to be with the third
report (ie AntStabBVDS) because it is this report that keeps opening, even
after I have selected "rotator cuff repair" in the combo box on the
"Operation" form. I have checked that the spelling in the value list of the
combo box is the same as in the code below.


Anthony
'*********************************************************
Private Sub Command15_Click()

Dim StDocName1 As String
Dim StDocName2 As String
Dim StDocName3 As String
Dim strWhere As String
Dim stLinkCriteria As String
Dim frmF As Form

Set frmF = Form_Operation
frmF.Refresh

StDocName1 = "DHSBVDS"
StDocName2 = "RotCuffBVDS"
StDocName3 = "AntStabBVDS"

stLinkCriteria = "[PatientID]=" & Me!PatientID
strWhere = "[PatientID]=" & Me!PatientID

If frmF.OperationType1 = "dynamic hipscrew and plate" Then

DoCmd.Close
DoCmd.OpenReport StDocName1, acViewPreview, , strWhere
DoCmd.Maximize

Else
If frmF.OperationType1 = "rotator cuff repair" Then

DoCmd.Close
DoCmd.OpenReport StDocName2, acViewPreview, , strWhere
DoCmd.Maximize

Else
If frmF.OperationType1 = "anterior stabilisation" Then

DoCmd.Close
DoCmd.OpenReport StDocName3, acViewPreview, , strWhere
DoCmd.Maximize

End If
End If
End If

Exit_Report_Click:
Exit Sub
'*****************************************************
 
M

Marshall Barton

Anthony said:
I have a form called "PostOpInstructions" which has on it a command button
that is supposed to open one of several different reports when pressed. The
code for this command button is shown below. The report that opens depends
on the value contained within a field (actually a combo box) called
"OperationType1", which is located on another form called "Operation". The
user enters data in the "Operation" form, then clicks on a command button to
open the "PostOpInstructions" form, in which more data is entered.

The problem is that the wrong report opens when I click the command button
on the "PostOpInstructions" form. The problem seems to be with the third
report (ie AntStabBVDS) because it is this report that keeps opening, even
after I have selected "rotator cuff repair" in the combo box on the
"Operation" form. I have checked that the spelling in the value list of the
combo box is the same as in the code below.

'*********************************************************
Private Sub Command15_Click()

Dim StDocName1 As String
Dim StDocName2 As String
Dim StDocName3 As String
Dim strWhere As String
Dim stLinkCriteria As String
Dim frmF As Form

Set frmF = Form_Operation
frmF.Refresh

StDocName1 = "DHSBVDS"
StDocName2 = "RotCuffBVDS"
StDocName3 = "AntStabBVDS"

stLinkCriteria = "[PatientID]=" & Me!PatientID
strWhere = "[PatientID]=" & Me!PatientID

If frmF.OperationType1 = "dynamic hipscrew and plate" Then

DoCmd.Close
DoCmd.OpenReport StDocName1, acViewPreview, , strWhere
DoCmd.Maximize

Else
If frmF.OperationType1 = "rotator cuff repair" Then

DoCmd.Close
DoCmd.OpenReport StDocName2, acViewPreview, , strWhere
DoCmd.Maximize

Else
If frmF.OperationType1 = "anterior stabilisation" Then

DoCmd.Close
DoCmd.OpenReport StDocName3, acViewPreview, , strWhere
DoCmd.Maximize

End If
End If
End If

Exit_Report_Click:
Exit Sub
'*****************************************************


Since that's the case that executes when all the conditions
fail, I would definitely suspect that the combo box value is
not what you think it is. Have you used a break point to
verify the combo's value?

Other than that, I think you might, maybe, possibly have an
issue with the form object reference in
Set frmF = Form_Operation

That syntax could be referencing a different instance of the
form's class module than the one you opened. Try using
Set frmF = Forms!Operation

Actually, I'm pretty sure that your procedure can be
reorganized to make it easier (at least for me) to see
what's happening.

Private Sub Command15_Click()
Dim StDocName As String
Dim strWhere As String

With Forms!Operation
.Refresh
MsgBox "---" & .OperationType1 & "---" 'only for test
Select Case .OperationType1
Case "dynamic hipscrew and plate"
StDocName = "DHSBVDS"
Case "rotator cuff repair"
StDocName = "RotCuffBVDS"
Case "anterior stabilisation"
StDocName = "AntStabBVDS"
Case Else
MsgBox "Something Funky Going On"
Exit Sub
End Select

strWhere = "[PatientID]=" & Me!PatientID

DoCmd.OpenReport StDocName, acViewPreview, , strWhere
DoCmd.Maximize
DoCmd.Close acForm, Me.Name, acSaveNo

Exit_Report_Click:
Exit Sub
 
A

Anthony

Hi Marsh

Thank you for your response. You may have been correct in guessing that the
problem was with "Set frmF = Form_Operation". I actually got the thing to
work correctly using the DLookup function to look up the value of
"OperationType1" in the "Operation" table.

Thanks again
Anthony

Marshall Barton said:
Anthony said:
I have a form called "PostOpInstructions" which has on it a command button
that is supposed to open one of several different reports when pressed. The
code for this command button is shown below. The report that opens depends
on the value contained within a field (actually a combo box) called
"OperationType1", which is located on another form called "Operation". The
user enters data in the "Operation" form, then clicks on a command button to
open the "PostOpInstructions" form, in which more data is entered.

The problem is that the wrong report opens when I click the command button
on the "PostOpInstructions" form. The problem seems to be with the third
report (ie AntStabBVDS) because it is this report that keeps opening, even
after I have selected "rotator cuff repair" in the combo box on the
"Operation" form. I have checked that the spelling in the value list of the
combo box is the same as in the code below.

'*********************************************************
Private Sub Command15_Click()

Dim StDocName1 As String
Dim StDocName2 As String
Dim StDocName3 As String
Dim strWhere As String
Dim stLinkCriteria As String
Dim frmF As Form

Set frmF = Form_Operation
frmF.Refresh

StDocName1 = "DHSBVDS"
StDocName2 = "RotCuffBVDS"
StDocName3 = "AntStabBVDS"

stLinkCriteria = "[PatientID]=" & Me!PatientID
strWhere = "[PatientID]=" & Me!PatientID

If frmF.OperationType1 = "dynamic hipscrew and plate" Then

DoCmd.Close
DoCmd.OpenReport StDocName1, acViewPreview, , strWhere
DoCmd.Maximize

Else
If frmF.OperationType1 = "rotator cuff repair" Then

DoCmd.Close
DoCmd.OpenReport StDocName2, acViewPreview, , strWhere
DoCmd.Maximize

Else
If frmF.OperationType1 = "anterior stabilisation" Then

DoCmd.Close
DoCmd.OpenReport StDocName3, acViewPreview, , strWhere
DoCmd.Maximize

End If
End If
End If

Exit_Report_Click:
Exit Sub
'*****************************************************


Since that's the case that executes when all the conditions
fail, I would definitely suspect that the combo box value is
not what you think it is. Have you used a break point to
verify the combo's value?

Other than that, I think you might, maybe, possibly have an
issue with the form object reference in
Set frmF = Form_Operation

That syntax could be referencing a different instance of the
form's class module than the one you opened. Try using
Set frmF = Forms!Operation

Actually, I'm pretty sure that your procedure can be
reorganized to make it easier (at least for me) to see
what's happening.

Private Sub Command15_Click()
Dim StDocName As String
Dim strWhere As String

With Forms!Operation
.Refresh
MsgBox "---" & .OperationType1 & "---" 'only for test
Select Case .OperationType1
Case "dynamic hipscrew and plate"
StDocName = "DHSBVDS"
Case "rotator cuff repair"
StDocName = "RotCuffBVDS"
Case "anterior stabilisation"
StDocName = "AntStabBVDS"
Case Else
MsgBox "Something Funky Going On"
Exit Sub
End Select

strWhere = "[PatientID]=" & Me!PatientID

DoCmd.OpenReport StDocName, acViewPreview, , strWhere
DoCmd.Maximize
DoCmd.Close acForm, Me.Name, acSaveNo

Exit_Report_Click:
Exit 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