Print code stopped working

G

Gabby Girl

Good morning,

I have the following code attached to a command button that up to yesterday
did what it was supposed to do (sort of):

********************************
Private Sub cmdPrint_Click()
On Error GoTo Err_cmdPrint_Click

Dim stDocName As String
Dim Cancel As Boolean

stDocName = "rptPickTicket"

If IsNull(Me.cboRONbr) or (Me.cboRONbr) = 0 Then
MsgBox "You must have a workorder nbr before you can print a pick
ticket!", vbOKOnly, "Stop!"
Exit Sub
End If

Else

DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenReport stDocName, acViewPreview, , "[qrptPickTicket].[PTId] =
" & Me![PTId]
Me.EquipmentId.SetFocus
Me.cmdPrint.Visible = False
Me.cmdAddPT.Visible = True

Exit_cmdPrint_Click:
Exit Sub

Err_cmdPrint_Click:
MsgBox Err.Description
Resume Exit_cmdPrint_Click

End Sub
*************************
I had to modify the above to allow certain pick tickets to print with
cboRONbr = 0
as long as the Equipment nbrs began with 3 certain letters.

Here is the modified code. Which now does nothing at all.

********************************
Private Sub cmdPrint_Click()
On Error GoTo Err_cmdPrint_Click

Dim stDocName As String
Dim Cancel As Boolean

stDocName = "rptPickTicket"

If Me.EquipmentId Like "*N*" Or Me.EquipmentId Like "*HV*" Or
Me.EquipmentId Like "*P*" And Me.cboRONbr = 0 Then

DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenReport stDocName, acViewPreview, , "[qrptPickTicket].[PTId] =
" & Me![PTId]
Me.EquipmentId.SetFocus
Me.cmdPrint.Visible = False
Me.cmdAddPT.Visible = True

ElseIf Nz(Me.cboRONbr) And Me.EquipmentId Like "*C*" Or Me.EquipmentId
Like "*CE*" Or Me.EquipmentId Like "*E*" Or Me.EquipmentId Like "*F*" Or
Me.EquipmentId Like "*R*" Then
MsgBox "You must have a workorder nbr before you can print a pick
ticket!", vbOKOnly, "Stop!"
Exit Sub

End If

Exit_cmdPrint_Click:
Exit Sub

Err_cmdPrint_Click:
MsgBox Err.Description
Resume Exit_cmdPrint_Click

End Sub
**********************************

Basically what we need is :

1) Print pick ticket if cboRONbr is 0 AND EquipmentId begins with either a
"N,"P' or HV"

2) Don't print pick ticket if cboRONbr is 0 AND EquipmentId begins with
anything other than the 3 listed above.

I've tried a variety of things suggested by others & can't seem to get
anything to work. I'm sure the solution is staring me in the face, but I
can't seem to figure it.

Any help, as always, will be greatly appreciated.

Thanks Kindly
 
C

Carl Rapson

Gabby Girl said:
Good morning,

I have the following code attached to a command button that up to
yesterday
did what it was supposed to do (sort of):

********************************
Private Sub cmdPrint_Click()
On Error GoTo Err_cmdPrint_Click

Dim stDocName As String
Dim Cancel As Boolean

stDocName = "rptPickTicket"

If IsNull(Me.cboRONbr) or (Me.cboRONbr) = 0 Then
MsgBox "You must have a workorder nbr before you can print a pick
ticket!", vbOKOnly, "Stop!"
Exit Sub
End If

Else

DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenReport stDocName, acViewPreview, , "[qrptPickTicket].[PTId] =
" & Me![PTId]
Me.EquipmentId.SetFocus
Me.cmdPrint.Visible = False
Me.cmdAddPT.Visible = True

Exit_cmdPrint_Click:
Exit Sub

Err_cmdPrint_Click:
MsgBox Err.Description
Resume Exit_cmdPrint_Click

End Sub
*************************
I had to modify the above to allow certain pick tickets to print with
cboRONbr = 0
as long as the Equipment nbrs began with 3 certain letters.

Here is the modified code. Which now does nothing at all.

********************************
Private Sub cmdPrint_Click()
On Error GoTo Err_cmdPrint_Click

Dim stDocName As String
Dim Cancel As Boolean

stDocName = "rptPickTicket"

If Me.EquipmentId Like "*N*" Or Me.EquipmentId Like "*HV*" Or
Me.EquipmentId Like "*P*" And Me.cboRONbr = 0 Then

DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenReport stDocName, acViewPreview, , "[qrptPickTicket].[PTId] =
" & Me![PTId]
Me.EquipmentId.SetFocus
Me.cmdPrint.Visible = False
Me.cmdAddPT.Visible = True

ElseIf Nz(Me.cboRONbr) And Me.EquipmentId Like "*C*" Or Me.EquipmentId
Like "*CE*" Or Me.EquipmentId Like "*E*" Or Me.EquipmentId Like "*F*" Or
Me.EquipmentId Like "*R*" Then
MsgBox "You must have a workorder nbr before you can print a pick
ticket!", vbOKOnly, "Stop!"
Exit Sub

End If

Exit_cmdPrint_Click:
Exit Sub

Err_cmdPrint_Click:
MsgBox Err.Description
Resume Exit_cmdPrint_Click

End Sub
**********************************

Basically what we need is :

1) Print pick ticket if cboRONbr is 0 AND EquipmentId begins with either a
"N,"P' or HV"

2) Don't print pick ticket if cboRONbr is 0 AND EquipmentId begins with
anything other than the 3 listed above.

I've tried a variety of things suggested by others & can't seem to get
anything to work. I'm sure the solution is staring me in the face, but I
can't seem to figure it.

Any help, as always, will be greatly appreciated.

Thanks Kindly

Add parentheses in your WHERE clauses:

If (Me.EquipmentId Like "*N*" Or Me.EquipmentId Like "*HV*" Or
Me.EquipmentId Like "*P*") And Me.cboRONbr = 0 Then

and

ElseIf Nz(Me.cboRONbr) And (Me.EquipmentId Like "*C*" Or Me.EquipmentId Like
"*CE*" Or Me.EquipmentId Like "*E*" Or Me.EquipmentId Like "*F*" Or
Me.EquipmentId Like "*R*") Then

In your ElseIf, did you mean to use Nz or did you want to use IsNull, as in
the first example (the one that "sort of" worked)?

ElseIf IsNull(Me.cboRONbr) ...


Carl Rapson
 
G

Gabby Girl

Hi Carl,

Thank you for taking the time to help me. I have to step out of the office
for a few minutes but I will try your suggestion as soon as I get back & let
you know how it goes.

Thanks


Carl Rapson said:
Gabby Girl said:
Good morning,

I have the following code attached to a command button that up to
yesterday
did what it was supposed to do (sort of):

********************************
Private Sub cmdPrint_Click()
On Error GoTo Err_cmdPrint_Click

Dim stDocName As String
Dim Cancel As Boolean

stDocName = "rptPickTicket"

If IsNull(Me.cboRONbr) or (Me.cboRONbr) = 0 Then
MsgBox "You must have a workorder nbr before you can print a pick
ticket!", vbOKOnly, "Stop!"
Exit Sub
End If

Else

DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenReport stDocName, acViewPreview, , "[qrptPickTicket].[PTId] =
" & Me![PTId]
Me.EquipmentId.SetFocus
Me.cmdPrint.Visible = False
Me.cmdAddPT.Visible = True

Exit_cmdPrint_Click:
Exit Sub

Err_cmdPrint_Click:
MsgBox Err.Description
Resume Exit_cmdPrint_Click

End Sub
*************************
I had to modify the above to allow certain pick tickets to print with
cboRONbr = 0
as long as the Equipment nbrs began with 3 certain letters.

Here is the modified code. Which now does nothing at all.

********************************
Private Sub cmdPrint_Click()
On Error GoTo Err_cmdPrint_Click

Dim stDocName As String
Dim Cancel As Boolean

stDocName = "rptPickTicket"

If Me.EquipmentId Like "*N*" Or Me.EquipmentId Like "*HV*" Or
Me.EquipmentId Like "*P*" And Me.cboRONbr = 0 Then

DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenReport stDocName, acViewPreview, , "[qrptPickTicket].[PTId] =
" & Me![PTId]
Me.EquipmentId.SetFocus
Me.cmdPrint.Visible = False
Me.cmdAddPT.Visible = True

ElseIf Nz(Me.cboRONbr) And Me.EquipmentId Like "*C*" Or Me.EquipmentId
Like "*CE*" Or Me.EquipmentId Like "*E*" Or Me.EquipmentId Like "*F*" Or
Me.EquipmentId Like "*R*" Then
MsgBox "You must have a workorder nbr before you can print a pick
ticket!", vbOKOnly, "Stop!"
Exit Sub

End If

Exit_cmdPrint_Click:
Exit Sub

Err_cmdPrint_Click:
MsgBox Err.Description
Resume Exit_cmdPrint_Click

End Sub
**********************************

Basically what we need is :

1) Print pick ticket if cboRONbr is 0 AND EquipmentId begins with either a
"N,"P' or HV"

2) Don't print pick ticket if cboRONbr is 0 AND EquipmentId begins with
anything other than the 3 listed above.

I've tried a variety of things suggested by others & can't seem to get
anything to work. I'm sure the solution is staring me in the face, but I
can't seem to figure it.

Any help, as always, will be greatly appreciated.

Thanks Kindly

Add parentheses in your WHERE clauses:

If (Me.EquipmentId Like "*N*" Or Me.EquipmentId Like "*HV*" Or
Me.EquipmentId Like "*P*") And Me.cboRONbr = 0 Then

and

ElseIf Nz(Me.cboRONbr) And (Me.EquipmentId Like "*C*" Or Me.EquipmentId Like
"*CE*" Or Me.EquipmentId Like "*E*" Or Me.EquipmentId Like "*F*" Or
Me.EquipmentId Like "*R*") Then

In your ElseIf, did you mean to use Nz or did you want to use IsNull, as in
the first example (the one that "sort of" worked)?

ElseIf IsNull(Me.cboRONbr) ...


Carl Rapson
 
G

Gabby Girl

Hi again Carl,

Thank you, thank you, thank you!

I finally got your code to work. And yes you're correct I did want to use
IsNull.
I think I was too busy confusing myself with null and 0 that I couldn't keep
anything straight anymore.

Again a BIG thank you. I really apreciate it.

Have a great day.

Gabby Girl said:
Hi Carl,

Thank you for taking the time to help me. I have to step out of the office
for a few minutes but I will try your suggestion as soon as I get back & let
you know how it goes.

Thanks


Carl Rapson said:
Gabby Girl said:
Good morning,

I have the following code attached to a command button that up to
yesterday
did what it was supposed to do (sort of):

********************************
Private Sub cmdPrint_Click()
On Error GoTo Err_cmdPrint_Click

Dim stDocName As String
Dim Cancel As Boolean

stDocName = "rptPickTicket"

If IsNull(Me.cboRONbr) or (Me.cboRONbr) = 0 Then
MsgBox "You must have a workorder nbr before you can print a pick
ticket!", vbOKOnly, "Stop!"
Exit Sub
End If

Else

DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenReport stDocName, acViewPreview, , "[qrptPickTicket].[PTId] =
" & Me![PTId]
Me.EquipmentId.SetFocus
Me.cmdPrint.Visible = False
Me.cmdAddPT.Visible = True

Exit_cmdPrint_Click:
Exit Sub

Err_cmdPrint_Click:
MsgBox Err.Description
Resume Exit_cmdPrint_Click

End Sub
*************************
I had to modify the above to allow certain pick tickets to print with
cboRONbr = 0
as long as the Equipment nbrs began with 3 certain letters.

Here is the modified code. Which now does nothing at all.

********************************
Private Sub cmdPrint_Click()
On Error GoTo Err_cmdPrint_Click

Dim stDocName As String
Dim Cancel As Boolean

stDocName = "rptPickTicket"

If Me.EquipmentId Like "*N*" Or Me.EquipmentId Like "*HV*" Or
Me.EquipmentId Like "*P*" And Me.cboRONbr = 0 Then

DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenReport stDocName, acViewPreview, , "[qrptPickTicket].[PTId] =
" & Me![PTId]
Me.EquipmentId.SetFocus
Me.cmdPrint.Visible = False
Me.cmdAddPT.Visible = True

ElseIf Nz(Me.cboRONbr) And Me.EquipmentId Like "*C*" Or Me.EquipmentId
Like "*CE*" Or Me.EquipmentId Like "*E*" Or Me.EquipmentId Like "*F*" Or
Me.EquipmentId Like "*R*" Then
MsgBox "You must have a workorder nbr before you can print a pick
ticket!", vbOKOnly, "Stop!"
Exit Sub

End If

Exit_cmdPrint_Click:
Exit Sub

Err_cmdPrint_Click:
MsgBox Err.Description
Resume Exit_cmdPrint_Click

End Sub
**********************************

Basically what we need is :

1) Print pick ticket if cboRONbr is 0 AND EquipmentId begins with either a
"N,"P' or HV"

2) Don't print pick ticket if cboRONbr is 0 AND EquipmentId begins with
anything other than the 3 listed above.

I've tried a variety of things suggested by others & can't seem to get
anything to work. I'm sure the solution is staring me in the face, but I
can't seem to figure it.

Any help, as always, will be greatly appreciated.

Thanks Kindly

Add parentheses in your WHERE clauses:

If (Me.EquipmentId Like "*N*" Or Me.EquipmentId Like "*HV*" Or
Me.EquipmentId Like "*P*") And Me.cboRONbr = 0 Then

and

ElseIf Nz(Me.cboRONbr) And (Me.EquipmentId Like "*C*" Or Me.EquipmentId Like
"*CE*" Or Me.EquipmentId Like "*E*" Or Me.EquipmentId Like "*F*" Or
Me.EquipmentId Like "*R*") Then

In your ElseIf, did you mean to use Nz or did you want to use IsNull, as in
the first example (the one that "sort of" worked)?

ElseIf IsNull(Me.cboRONbr) ...


Carl Rapson
 

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