Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi all,

 

I am trying to get a print dialog to display and get the following error. I am new to printing in .Net. The Access report prints using this but doesn't display a print dialog, when I don't have "Me.PrintDialog1.ShowDialog()" in the procedure. Please help.

 

"An unhandled exception of type 'System.ArgumentException' occurred in system.windows.forms.dll

 

Additional information: PrintDialog needs a PrinterSettings object to display. Please set PrintDialog.Document (preferred) or PrintDialog.PrinterSettings."

 

Code is as follows:

 

Private Sub mnuFilePrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFilePrint.Click

Dim Acc As Access.Application

 

' Populate the print database table

Call PopPrintDB()

 

' Need to Select the Printer

Me.PrintDialog1.ShowDialog()

 

' Print a report named PrintSignOutForm

' Enable an error handler

On Error GoTo ErrorHandler

 

' Start a new instance of Access for Automation:

Acc = New Access.ApplicationClass

 

' Open the Database in shared mode:

Acc.OpenCurrentDatabase(strDatabaseName, False)

 

' Select the report name in the database window and give focus

' to the datbase window.

Acc.DoCmd.SelectObject(Access.AcObjectType.acReport, strReportName, True)

 

'Print the report

Acc.DoCmd.OpenReport(strReportName, Access.AcView.acViewNormal)

 

CleanUp:

' Quit Access and release object:

On Error Resume Next

Acc.Quit(Access.AcQuitOption.acQuitSaveNone)

System.Runtime.InteropServices.Marshal.ReleaseComObject(Acc)

Acc = Nothing

' Delete records in the PrintSignOut Table

 

Call DeletePrintedAsset()

Exit Sub

 

ErrorHandler:

MessageBox.Show("An error has occurred! " & Err.Number & ": " & Err.Description, _

"DIntTC Asset Management", MessageBoxButtons.OK, MessageBoxIcon.Error)

' Try to Quit Access due to an unexpected Error:

Resume CleanUp

End Sub

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

-- Rick Cook, The Wizardry Compiled

  • Administrators
Posted

The error message pretty much tells you what you need to change - before you can display the print dialog you need to assign a PrinterSettings object to it like so

       Dim ps As New Printing.PrinterSettings
       PrintDialog1.PrinterSettings = ps
       ' Need to Select the Printer
       Me.PrintDialog1.ShowDialog()

 

also if you are making the move to .Net I would recomend you look at structured exception handling - far superior to the old vb6 on error goto... method.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted (edited)

Thanks for that. :D

 

It now displays the print dialog but still uses the default printer not the selected one.

 

Normally I wouldn't use the error goto... method. But this was the only way I could find to print a MS Access Report off a MS website. Usually I would use the Try - Catch ex As Exception - End Try Method.

Edited by SonicBoomAu

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

-- Rick Cook, The Wizardry Compiled

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...