Can't compile in 2000, works in 2002

Dudley

Registered User.
Local time
Today, 11:33
Joined
Apr 7, 2004
Messages
147
I'm working in 2002 Developer on a 2000 file.

I'm creating reports and have a form where the user delineates a variety of criteria then clicks either a PREVIEW or PRINT button.

Preview button includes: CreateReports ("Preview")
Print button includes: CreateReports ("Normal")


Elsewhere in the form's module I have a module:

Private Sub CreateReports(PrintOrPreview As String)
... (irrelevant lines removed)

Select Case PrintOrPreview
Case "Preview"
DoCmd.OpenReport strNewReport, acViewPreview, , , acHidden
Case "Normal"
DoCmd.OpenReport strNewReport, acViewNormal, , , acHidden
End Select

If PrintOrPreview = "Preview" Then Reports(strNewReport).Visible = True
...(irrelevant lines removed)
end sub

When Access 2000 users click Preview, the code hangs up on the docmd.openreport line saying it can't compile the module.

I suspect the problem is with my PrintOrPreview variable.

Does anyone have any suggestions for how I can fix this code to work in 2000 while keeping this basic approach? Alternatively I'm thinking about a module-scope variable to hold "print" or "preview" value. I sure appreciate any help!!!!
 
My VBA is a tad rusty, but in languages like C/C++/Java, you cannot execute a Switch (Select Case) on a string.

Try This:

Code:
'Preview button includes: CreateReports (0)
'Print button includes: CreateReports (1)

'Elsewhere in the form's module I have a module:

Private Sub CreateReports(PrintOrPreview As Integer)

'... (irrelevant lines removed)

Select Case PrintOrPreview
Case 0
DoCmd.OpenReport strNewReport, acViewPreview, , , acHidden
Case 1
DoCmd.OpenReport strNewReport, acViewNormal, , , acHidden
End Select

If PrintOrPreview = 0 Then Reports(strNewReport).Visible = True

'...(irrelevant lines removed)

End Sub
 
I suspect the problem is that A2k doesn't have that last argument (acHidden). I'm not clear on why you bother with it anyway, since you make it visible later.

For the record, Select/Case will handle strings fine.
 
ReAn said:
My VBA is a tad rusty, but in languages like C/C++/Java, you cannot execute a Switch (Select Case) on a string.

Actually, you can use a Select Case on a string in VB/VBA.
 
Thanks for your help, everybody. I kept the Select Case strings and got rid of the "acHidden" argument. I was originally initially hiding the report until I verified there were records in it (some of the removed code). Now I've moved that check in front of opening the report.
 
About the no data, you can use the NO DATA event of the report and if there is no data do something like this:

Code:
Private Sub Report_NoData(Cancel As Integer)
    MsgBox "There was no data to display", vbInformation, "NO DATA"
    Cancel = True
End Sub

And then you will need to trap for error 2501 in the code where you opened the report.
 
Thanks Bob! Is the "No Data" event available in Access2000? By the way, is there a place I can go to look up the arguments for eariler versions of Access? Thanks!!!
 

Users who are viewing this thread

Back
Top Bottom