Click here to Skip to main content
15,887,083 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My application was working fine. However, I needed to add some refinements which had nothing to do with the printing.
But now the code which printed a pdf copy of my EXCEL worksheet does not now work.
The code is
PrintForm1.PrinterSettings.PrinterName = "Microsoft Print to PDF"
        PrintForm1.PrintAction = Printing.PrintAction.PrintToPrinter

        If PrintForm1.PrinterSettings.IsValid Then
            PrinterName = PrintForm1.PrinterSettings.PrinterName
            oSheet.PrintOut(From:=1, To:=1, Copies:=1, ActivePrinter:=PrinterName, Collate:=True, Preview:=True)


I get this error message associated to the first line.
"System.NullReferenceException: 'Object reference not set to an instance of an object.'

MatchManagementApplication_2.InputForm.PrintForm1.get returned Nothing.
Any help greatly appreciated.
"

What I have tried:

I have Imported Microsoft.VisualBasic.PowerPacks.Printing but the code stated it was not required.
Changed to Microsoft.VisualBasic.PowerPacks then a new error message came up on the second line of code, stating Error BC30456 'PrintAction' is not a member of 'Microsoft.VisualBasic.PowerPacks.Printing'.
Commented out the second line of code but the first line still fails when the code is run.
Posted
Updated 27-Nov-17 22:38pm

1 solution

System.NullReferenceException is one of the most common errors we see reported here. It means that you are trying to use an object reference that has not been initialised. The only way to find out where and why is to use your debugger to step through your code.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900