Creating a string to run reports

G

Guest

I have created a string of code to have the buttom run a group of report
determined on what the user selects. However, when I add the combox using
the field Record ID it will not work. When I us all the other option by them
self or as a group they will work. But as soon as I add the Record ID it
will not work. The Record ID is a autonumber field. It is how I save the
records. Can anyone look at the code and see if they have any suggestions.

Private Sub CmdSafety_Click()
Dim stDocNameSRBF As String
Dim stDocNameSRBI As String
Dim stDocNameSRBN As String
Dim stDocNameSRBT As String


FM = Me!CboFM
ID = Me!CboID
NH = Me!CboNH
Trade = Me!CboTrade

'All reports for Safety Report request
stDocNameSRBF = "SafetyReportbyFM"
stDocNameSRBI = "SafetyReportbyID"
stDocNameSRBN = "SafetyReportbyNH"
stDocNameSRBT = "SafetyReportbyTrade"

'This select the correct report by what cbo field is selected.
If ID = Null And NH = "" And Trade = "" Then
DoCmd.OpenReport stDocNameSRBF, acViewPreview
End If

If FM = "" And NH = "" And Trade = "" Then
DoCmd.OpenReport stDocNameSRBI, acViewPreview
End If

If FM = "" And D = "" And Trade = "" Then
DoCmd.OpenReport stDocNameSRBN, acViewPreview
End If

If FM = "" And ID = "" And NH = "" Then
DoCmd.OpenReport stDocNameSRBT, acViewPreview
End If

If FM = "" And ID = "" And NH = "" And Trade = "" Then
MsgBox "You must select a field to generate a report."
End If

End Sub
 
G

Guest

Since the Record ID is an autonumber, there will be only one record with the
value you enter or there will be no record if you enter a number that does
not exist in that field. Also, If you choose a RecordID, the other filter
criteria are pretty much meaningless. It is most likely you are completely
filtering out an return.

I would suggest you rewrite your code to select either by record number or
by a combination of the other fields.
 
G

Guest

What you are tring to say is remove the Autonumber field from the string and
create on for just that. Correct?
 
G

Guest

Yes.
One other thing to consider it how you are checking the values of the
combos. An uninitialized combo will return Null. Since you are populating
your string variables with the value in the combo, you run the risk of
receiving an "Invalid Use of Null" error. To protect against this, you may
want to consider:

FM = Nz(Me!CboFM, "")
 

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