Taking on a sense of urgency....

  • Thread starter Thread starter yoda jedi
  • Start date Start date
Y

yoda jedi

I have 3 reports to run via one report. Basically, the users don't
want the interface changed. BUT for companies A and B, they want
changed reports. So I created reports A and B, respectively.

So I wrote the code to, if companies A or B were selected, close the
current report (which is for all other companies), and open reports A
or B.

[This is SORT of a solution, because when they ask to print a report,
they can only get a print preview of A or B, and the original report
prints out on the printer. Think of it as one report routing to
itself, A or B, depending on the selection of company.]

But nevermind that! They're getting a print preview, they can print
it out their damn selves if they want!!!

Ok, so... Now that I'm cancelling an event, I have to supress the
message. I've been all over the group, it seems fairly clear what the
solution is, so why doesn't it work when implemented? I am
compromising enough quality by saying that they have to print the
reports for A and B manually. I can't ask them to accept a message
box that looks to them like the report has a bug or an error.

My question is... I mostly want now to suppress the message box.
=============================================================

Option Compare Database
Option Explicit
Public strCompany As String
Public lview As Integer

Private Sub Report_NoData(Cancel As Integer)
DoCmd.SetWarnings False
Cancel = True
End Sub

Private Sub Report_Open(Cancel As Integer)
On Error GoTo Report_Open_Error
Dim rsQuery As Recordset
Dim dStartDate, dEndDate As Date

Set rsQuery = DBEngine.Workspaces(0).Databases(0).OpenRecordset( _
"SELECT * FROM tThirdPartyReport_Params")

lview = acViewPreview

If Not rsQuery.EOF Then
dStartDate = rsQuery!StartDate
dEndDate = rsQuery!EndDate
strCompany = rsQuery!Company
End If

DoCmd.SetWarnings False

Select Case UCase(Trim(strCompany))
Case "A"
Me.Visible = False
'''DoCmd.CancelEvent
Cancel = True
DoCmd.OpenReport "ThirdParty Report_A", lview
Case "B"
Me.Visible = False
'''DoCmd.CancelEvent
Cancel = True
DoCmd.OpenReport "ThirdParty Report_B", lview
Case Else
End Select
Err.Clear

Exit Sub
Report_Open_Error:
If Err.Number = 2501 Then
Err.Clear
Resume Next
End If

End Sub
 
Instead of using a Case statement why not use an If...Then statement.

Like...
Dim strCompany as string
strCompany = UCase(Trim(me.Companyname)

If strCompany = "A" then
docmd.openreport..........A
Else 'or you can add an
ElseIf strCompany = "B" then (if you had more than 2 reports.)
docmd.openreport..........B
End if

When they click a the buttom to preview the report it will look at the
company name in the form and preview the correct report. I don't understand
why you would have to use cancelevent. The only event I would cancel is if
there was no data in the report.

I don't think you need to create a recordset just to obtain a StartDate,
EndDate and Company name. Wouldn't it just be easier to have a form with
this infomation or maybe add a few InputBox() functions to gather some info.

Just a suggestion.
Evy


yoda jedi said:
I have 3 reports to run via one report. Basically, the users don't
want the interface changed. BUT for companies A and B, they want
changed reports. So I created reports A and B, respectively.

So I wrote the code to, if companies A or B were selected, close the
current report (which is for all other companies), and open reports A
or B.

[This is SORT of a solution, because when they ask to print a report,
they can only get a print preview of A or B, and the original report
prints out on the printer. Think of it as one report routing to
itself, A or B, depending on the selection of company.]

But nevermind that! They're getting a print preview, they can print
it out their damn selves if they want!!!

Ok, so... Now that I'm cancelling an event, I have to supress the
message. I've been all over the group, it seems fairly clear what the
solution is, so why doesn't it work when implemented? I am
compromising enough quality by saying that they have to print the
reports for A and B manually. I can't ask them to accept a message
box that looks to them like the report has a bug or an error.

My question is... I mostly want now to suppress the message box.
=============================================================

Option Compare Database
Option Explicit
Public strCompany As String
Public lview As Integer

Private Sub Report_NoData(Cancel As Integer)
DoCmd.SetWarnings False
Cancel = True
End Sub

Private Sub Report_Open(Cancel As Integer)
On Error GoTo Report_Open_Error
Dim rsQuery As Recordset
Dim dStartDate, dEndDate As Date

Set rsQuery = DBEngine.Workspaces(0).Databases(0).OpenRecordset( _
"SELECT * FROM tThirdPartyReport_Params")

lview = acViewPreview

If Not rsQuery.EOF Then
dStartDate = rsQuery!StartDate
dEndDate = rsQuery!EndDate
strCompany = rsQuery!Company
End If

DoCmd.SetWarnings False

Select Case UCase(Trim(strCompany))
Case "A"
Me.Visible = False
'''DoCmd.CancelEvent
Cancel = True
DoCmd.OpenReport "ThirdParty Report_A", lview
Case "B"
Me.Visible = False
'''DoCmd.CancelEvent
Cancel = True
DoCmd.OpenReport "ThirdParty Report_B", lview
Case Else
End Select
Err.Clear

Exit Sub
Report_Open_Error:
If Err.Number = 2501 Then
Err.Clear
Resume Next
End If

End Sub
 
Back
Top