Question Error Handling?

Nic

Registered User.
Local time
Today, 01:11
Joined
Jan 15, 2012
Messages
47
Hi,
Im having some issues with some code and i would be grateful for a bit of advice if you can decipher what i am trying to do from the below code! In summary, this code works once, and then if i force an error again, i get a data mismatch error and am prompted to End or Debug. Clearly something is wrong!

Let me know if I need to explain what i am trying to achieve......this is my code at present:

Private Sub PrintBarcodeToggle_Click()
If Me.PrintBarcodeToggle = True Then
Me.Qty.Visible = True
Me.Qty.SetFocus
Me.Del.Enabled = True
Me.PrintBarcodeToggle.Caption = "Confirm Print"
Me.PrintBarcodeToggle.ForeColor = vbRed

Else
Me.Qty.Visible = False
End If

If Me.PrintBarcodeToggle = False Then

If IsNull(Me.Qty) Then

Me.PrintBarcodeToggle = True
Me.Qty.Visible = True
MsgBox "Please enter a valid qty to print"
Me.Qty = ""
Me.Qty.SetFocus


Else

DoCmd.OpenReport "50x50", acViewPreview
DoCmd.PrintOut , , , , Me.Qty.Value
DoCmd.close
Me.PrintBarcodeToggle.Caption = "Barcode Only"
Me.PrintBarcodeToggle.ForeColor = vbBlack


Me.Qty = ""
Me.Qty.Visible = False
Me.No1.SetFocus
Me.MultiPrint.Visible = False
Me.Del.Enabled = False

End If

End If

End Sub



Suggestions greatly welcome!
Many thanks,
 
Try:
Code:
Private Sub PrintBarcodeToggle_Click()
If Me.PrintBarcodeToggle = True Then
  Me.Qty.Visible = True
  Me.Qty.SetFocus
  Me.Del.Enabled = True
  Me.PrintBarcodeToggle.Caption = "Confirm Print"
  Me.PrintBarcodeToggle.ForeColor = vbRed

Else
  Me.Qty.Visible = False

  If IsNull(Me.Qty) Then

    Me.PrintBarcodeToggle = True
    Me.Qty.Visible = True
    MsgBox "Please enter a valid qty to print"
    Me.Qty = ""
    Me.Qty.SetFocus


  Else

    DoCmd.OpenReport "50x50", acViewPreview
    DoCmd.PrintOut , , , , Me.Qty.Value
    DoCmd.close
    Me.PrintBarcodeToggle.Caption = "Barcode Only"
    Me.PrintBarcodeToggle.ForeColor = vbBlack

    Me.Qty = ""
    Me.Qty.Visible = False
    Me.No1.SetFocus
    Me.MultiPrint.Visible = False
    Me.Del.Enabled = False

  End If

End If

End Sub
 
Thanks, but still not working. I get the same error and when i debug, this line is highlighted:

DoCmd.PrintOut , , , , Me.Qty.Value

?? Still scratching my head over this!
 
How about changing

DoCmd.Close

to this:

DoCmd.Close acReport, "50x50", False
 
Thanks, but still not working. I get the same error and when i debug, this line is highlighted:

DoCmd.PrintOut , , , , Me.Qty.Value

?? Still scratching my head over this!
I hadn't noticed that line of code.
What are you trying to do with it.
 
Hi, thanks for the help, Just tried suggestion by SOS - still no luck!

Re. last post:

I have a text box, (Me.Qty), and the user should input a number into that text box. So that line of code prints my report the number of times as specified in Me.Qty.
If however the user doesnt input any number into Me.Qty, i need the If IsNull with a msg box telling them to put a number in the box!
Hope this explanation helps??

Thanks,
 
I just got it (I think):

You are using this:

Me.Qty = ""

But using this:

If IsNull(Me.Qty) Then

"" is not the same as Null. That is an empty string (zero length string). Try using this:

If Len(Me.Qty & vbNullString) = 0 Then
 
great!
Thanks, i think this has just solved my issue!
 

Users who are viewing this thread

Back
Top Bottom