stop code if address not there (1 Viewer)

rainbows

Registered User.
Local time
Today, 08:44
Joined
Apr 21, 2017
Messages
425
below is the code someone helped me with a while ago but i have now got a problem that

i would like to stop this give an error message if the address attached to the line number is not there in the table. i have discovered that people are not entering it and the reports are blank

So if i have an invoice for customer id no 149 the report will be ok but if i create another on say for customer id 150 . but there is no "address no" or information in the fields. i would like a message telling me

thanks
steve


Code:
Private Sub cmdOpenInvoice_Click()


    On Error GoTo Err_Handler
    
    Const MESSAGE_TEXT = "No current invoice."
 If Not IsNull([Invoice].[Form]![InvoiceNo]) Then
    
        ' ensure current record is saved
        Me.Dirty = False
        
         Me.addressno = InputBox("Please provide address line number")
        ' open report in print preview
        DoCmd.OpenReport "Invoice report", View:=acViewPreview
    Else
        MsgBox MESSAGE_TEXT, vbExclamation, "Invalid Operation"
    End If
    
Exit_Here:
    Exit Sub
    
Err_Handler:
    MsgBox Err.Description
    Resume Exit_Here
End Sub



1666854670905.png
 

Minty

AWF VIP
Local time
Today, 16:44
Joined
Jul 26, 2013
Messages
10,371
Why not give the user a list/combo of available addresses for that customer on the form, and not process the rest of the print command if it's not selected?

Asking them to know what address line no it is off the top of their heads seems a bit strange, and they could type anything into an input box that wasn't a valid choice. Take out the uncertainty in the process.
 

June7

AWF VIP
Local time
Today, 07:44
Joined
Mar 9, 2014
Messages
5,474
Where is this code? Why do you show a table and not a form?

Data should be validated during data entry, not reporting.
 

Gasman

Enthusiastic Amateur
Local time
Today, 16:44
Joined
Sep 21, 2011
Messages
14,311
Shutting the barn doors after the horse has bolted aren't we :)

As mentioned, you should have data validation that prevents that happening.

As a stop gap, produce a report for records that have no address, and pass back t the user to rectify.?

Plus InputBoxes are very limited. Again as mentioned a form would be a much better option.
 

Users who are viewing this thread

Top Bottom