D
DJG872
I need to print different reports depending upon criteria. I have a sample
request which may or may not contain more than 1 item on the request. The
criteria determines which report needs to be printed.
Following is my code:
---------------------------
Private Sub btnOpenApprovals_Click()
On Error GoTo Err_btnOpenApprovals_Click
Dim MyRecSet As Object
Dim intCountSamples As Integer
Set MyRecSet = CurrentDb.OpenRecordset("SELECT * FROM DT_SAMPLE_ITEMS
WHERE SAMPLEID = " & Me!SAMPLEID.Value)
MyRecSet.MoveLast
For intCountSamples = 1 To MyRecSet.RecordCount
If MyRecSet!FINISHID = 6 Then
DoCmd.OpenReport "R_SAMPLE_SF", acViewPreview, ,
"SAMPLEID = " & Me!SAMPLEID.Value
ElseIf MyRecSet!QUANTITY = 4 Then
If MyRecSet!TYPEID = 2 Then
DoCmd.OpenReport
"R_SAMPLE_4_FULL", acViewPreview, , "SAMPLEID = " & Me!SAMPLEID.Value
Else
DoCmd.OpenReport "R_SAMPLE_4",
acViewPreview, , "SAMPLEID = " & Me!SAMPLEID.Value
End If
ElseIf MyRecSet!QUANTITY = 5 Then
If MyRecSet!TYPEID = 2 Then
DoCmd.OpenReport
"R_SAMPLE_5_FULL", acViewPreview, , "SAMPLEID = " & Me!SAMPLEID.Value
Else
DoCmd.OpenReport "R_SAMPLE_5",
acViewPreview, , "SAMPLEID = " & Me!SAMPLEID.Value
End If
ElseIf MyRecSet!QUANTITY = 6 Then
If MyRecSet!TYPEID = 2 Then
DoCmd.OpenReport
"R_SAMPLE_6_FULL", acViewPreview, , "SAMPLEID = " & Me!SAMPLEID.Value
Else
DoCmd.OpenReport "R_SAMPLE_6",
acViewPreview, , "SAMPLEID = " & Me!SAMPLEID.Value
End If
ElseIf MyRecSet!QUANTITY = 8 Then
If MyRecSet!TYPEID = 2 Then
DoCmd.OpenReport
"R_SAMPLE_8_FULL", acViewPreview, , "SAMPLEID = " & Me!SAMPLEID.Value
Else
DoCmd.OpenReport "R_SAMPLE_8",
acViewPreview, , "SAMPLEID = " & Me!SAMPLEID.Value
End If
End If
Next intCountSamples
MyRecSet.Close
Exit_btnOpenApprovals_Click:
Exit Sub
Err_btnOpenApprovals_Click:
MsgBox Err.DESCRIPTION
Resume Exit_btnOpenApprovals_Click
End Sub
---------------------------------------
If I use 1 report the loop works fine but if the first if statement is false
then I receive the message Item not in collection. I don't what to have the
user to have to make the decision as to which reports are needed.
Any ideas, thoughts, help would be appreciated.
Thank you.
request which may or may not contain more than 1 item on the request. The
criteria determines which report needs to be printed.
Following is my code:
---------------------------
Private Sub btnOpenApprovals_Click()
On Error GoTo Err_btnOpenApprovals_Click
Dim MyRecSet As Object
Dim intCountSamples As Integer
Set MyRecSet = CurrentDb.OpenRecordset("SELECT * FROM DT_SAMPLE_ITEMS
WHERE SAMPLEID = " & Me!SAMPLEID.Value)
MyRecSet.MoveLast
For intCountSamples = 1 To MyRecSet.RecordCount
If MyRecSet!FINISHID = 6 Then
DoCmd.OpenReport "R_SAMPLE_SF", acViewPreview, ,
"SAMPLEID = " & Me!SAMPLEID.Value
ElseIf MyRecSet!QUANTITY = 4 Then
If MyRecSet!TYPEID = 2 Then
DoCmd.OpenReport
"R_SAMPLE_4_FULL", acViewPreview, , "SAMPLEID = " & Me!SAMPLEID.Value
Else
DoCmd.OpenReport "R_SAMPLE_4",
acViewPreview, , "SAMPLEID = " & Me!SAMPLEID.Value
End If
ElseIf MyRecSet!QUANTITY = 5 Then
If MyRecSet!TYPEID = 2 Then
DoCmd.OpenReport
"R_SAMPLE_5_FULL", acViewPreview, , "SAMPLEID = " & Me!SAMPLEID.Value
Else
DoCmd.OpenReport "R_SAMPLE_5",
acViewPreview, , "SAMPLEID = " & Me!SAMPLEID.Value
End If
ElseIf MyRecSet!QUANTITY = 6 Then
If MyRecSet!TYPEID = 2 Then
DoCmd.OpenReport
"R_SAMPLE_6_FULL", acViewPreview, , "SAMPLEID = " & Me!SAMPLEID.Value
Else
DoCmd.OpenReport "R_SAMPLE_6",
acViewPreview, , "SAMPLEID = " & Me!SAMPLEID.Value
End If
ElseIf MyRecSet!QUANTITY = 8 Then
If MyRecSet!TYPEID = 2 Then
DoCmd.OpenReport
"R_SAMPLE_8_FULL", acViewPreview, , "SAMPLEID = " & Me!SAMPLEID.Value
Else
DoCmd.OpenReport "R_SAMPLE_8",
acViewPreview, , "SAMPLEID = " & Me!SAMPLEID.Value
End If
End If
Next intCountSamples
MyRecSet.Close
Exit_btnOpenApprovals_Click:
Exit Sub
Err_btnOpenApprovals_Click:
MsgBox Err.DESCRIPTION
Resume Exit_btnOpenApprovals_Click
End Sub
---------------------------------------
If I use 1 report the loop works fine but if the first if statement is false
then I receive the message Item not in collection. I don't what to have the
user to have to make the decision as to which reports are needed.
Any ideas, thoughts, help would be appreciated.
Thank you.