My collection of things.

jKafer on the Net

April 19th, 2017 at 11:43 am

Access/VB do not print report with no data

Just a little bit of programming..after all it pays the bills.

I had setup the option to print different reports, depending on if something is manufactured in house or outsourced.  So I came up with this:

The code behind the button on the form:


Private Sub cmdPrintReport_click()

    On Error GoTo CatchErrNo

     
    If Me.JobNo > “” Then DoCmd.OpenReport “rptWorkOrder”, acViewPreview, , “JobNo = ” & Me.JobNo

 

CatchErrNo:

    If Err.Number > 0 Then
        ‘report will not open if there is no data, but throws an error. This will catch that error and print the workorder instead
        ‘jk – 4/18/2017
        If Err.Number = 2501 Then
            If Me.JobNo > “” Then DoCmd.OpenReport “rptPickList”, acViewPreview, , “JobNo = ” & Me.JobNo
        Else
            MsgBox Err.Number & ” – ” & Err.Description
        End If
    End If

End Sub


In the report design mode, you have to tell it what to do with no data (I never knew this was here)

Report – Event – On No Data


Private Sub Report_NoData(Cancel As Integer)
   Cancel = True
End Sub


Are there other ways to do this, yes, probably 100, but this is what works in the environment that I’m working in.

-

Comments are closed.


  • Count per Day

    • 11Visitors today:
    • 33Visitors per day:
    • 0Visitors currently online:
  • ScrapBook Software - MyMemoriesSuite
  • Latest Pins on Pinterest

    • @suppose_quilts I totally OMG'd outloud when I saw this quilt! I love it! By @suppose_quilts "It just snowed here but we're pretending it's spring. Pattern: Amsterdam, free at cloud9fabrics.com. Fabric: Pam Kitty Garden" via @PhotoRepost_app

    • Striking Strip Quilts: 16 Amazing Patterns for 2 1/2"-Strip Lovers: Kate Henderson: Jelly roll tulip quilt. Flower quilt pattern. affiliate link.

    • Fall Table Runner | from Marta with love http://frommartawithlove.com/fall-table-runner/

    • Scrappy Butterfly Baby Quilt Tutorial | Let your imagination take flight with this baby quilt!

    • All In A Row Again!

    • Feathered stars are fun to quilt! #freemotionquilting #longarmquilting #quiltedthistle

    • Westalee - Curly Q's

    • 18 Easy tutorials for making your own fabric labels at home. Click through to browse the list! DIY Crush

    • 6a0120a5f3f908970b015437f40faf970c-pi 3,312×4,416 pixels