Andy_CD
Bumbling Idiot
- Local time
- Today, 11:58
- Joined
- Feb 6, 2017
- Messages
- 23
Hi All,
I am trying to use the following code to print out a report. And then based on if other parts are present print another report.
It all works beautifully, unless the second part is missing then it prints double the number of copies of the first report.
I have switched the code around, but when I do this it prints the number of copies required according to my settings, but it then also prints the input form.
I'm very new to this so have probably made the code more complicated than it needs to be. Any help/suggestions gratefully received!
Private Sub Command21_Click()
On Error Resume Next
DoCmd.RunCommand acCmdSaveRecord
If ([Forms]![Form Label BRI]![Drug].Column(1) = 0) Then
DoCmd.OpenReport "Label BRI", acViewPreview, "", "[Hospital Number]=[Hospital Number]", acNormal
DoCmd.SelectObject acReport, "Label BRI"
If [Forms]![Form Label BRI]![Pack or Dose Unit] = "Pack(s)" Then
DoCmd.PrintOut acSelection, , , , [Forms]![Form Label BRI]![Quantity].Value
Else: DoCmd.PrintOut acSelection, , , , , 1
End If
End If
If [Forms]![Form Label BRI]![Drug].Column(2) Like "*" Then
DoCmd.OpenReport "Label BRI Supp", acViewPreview, "", "[Hospital Number]=[Hospital Number]", acNormal
DoCmd.SelectObject acReport, "Label BRI Supp"
End If
If [Forms]![Form Label BRI]![Pack or Dose Unit] = "Pack(s)" Then
DoCmd.PrintOut acSelection, , , , [Forms]![Form Label BRI]![Quantity].Value
Else: DoCmd.PrintOut acSelection, , , , , 1
End If
DoCmd.Close acReport, "Label BRI Supp"
DoCmd.Close acForm, "Form Label BRI"
DoCmd.Close acReport, "Label BRI"
End Sub
I am trying to use the following code to print out a report. And then based on if other parts are present print another report.
It all works beautifully, unless the second part is missing then it prints double the number of copies of the first report.
I have switched the code around, but when I do this it prints the number of copies required according to my settings, but it then also prints the input form.
I'm very new to this so have probably made the code more complicated than it needs to be. Any help/suggestions gratefully received!
Private Sub Command21_Click()
On Error Resume Next
DoCmd.RunCommand acCmdSaveRecord
If ([Forms]![Form Label BRI]![Drug].Column(1) = 0) Then
DoCmd.OpenReport "Label BRI", acViewPreview, "", "[Hospital Number]=[Hospital Number]", acNormal
DoCmd.SelectObject acReport, "Label BRI"
If [Forms]![Form Label BRI]![Pack or Dose Unit] = "Pack(s)" Then
DoCmd.PrintOut acSelection, , , , [Forms]![Form Label BRI]![Quantity].Value
Else: DoCmd.PrintOut acSelection, , , , , 1
End If
End If
If [Forms]![Form Label BRI]![Drug].Column(2) Like "*" Then
DoCmd.OpenReport "Label BRI Supp", acViewPreview, "", "[Hospital Number]=[Hospital Number]", acNormal
DoCmd.SelectObject acReport, "Label BRI Supp"
End If
If [Forms]![Form Label BRI]![Pack or Dose Unit] = "Pack(s)" Then
DoCmd.PrintOut acSelection, , , , [Forms]![Form Label BRI]![Quantity].Value
Else: DoCmd.PrintOut acSelection, , , , , 1
End If
DoCmd.Close acReport, "Label BRI Supp"
DoCmd.Close acForm, "Form Label BRI"
DoCmd.Close acReport, "Label BRI"
End Sub