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

    • 6Visitors today:
    • 34Visitors per day:
    • 1Visitors currently online:
  • ScrapBook Software - MyMemoriesSuite
  • Latest Pins on Pinterest

    • Pic-a-Word Letter Yard Dice Game by PicaNickandMore on Etsy

    • Bowling ball pool table!

    • I'm totally into this for a party idea. I love playing games at parties. This reminds of a party I had once where I created a life-sized boardgame in the backyard and had a "Mario Party" Party that was just like the video game. I wish I had pictures. ):

    • Cute Idea! Red Happiness is Homemade Faux Wood Plank Sign | Shop Hobby Lobby

    • Pet sign

    • Red Happiness is Homemade Faux Wood Plank Sign

    • Wood wall art, geometric wall art, wood home decor by AlaskaHaze on Etsy https://www.etsy.com/listing/227087749/wood-wall-art-geometric-wall-art-wood

    • Local Homemade Wooden Pallet Sign. Teal and Light Blue by KBRSigns, $25.00

    • Rustic Wooden Art Design Made From Reclaimed Wood

    • Love this block