Printing second time fails

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rick Lederman

    #1

    Printing second time fails

    I am using a PrintDocument and PrintDialog to print. The first time that I
    print it works, but when I try to print a second time without exiting the
    entire program I get an "InvalidPrinter Exception was unhandled" error. The
    error happens in the third line below. The details of the error are below
    my signature. Help?

    PrintDialog1.Pr interSettings.P rinterName = sLabelPrinterDe viceName

    PrintDialog1.Do cument = PrintDocument1

    PrintDialog1.Do cument.Print() ' the error happens in this line



    Any ideas?

    --
    Rick Lederman
    Soaring Software Solutions, Inc.
    Soaring Software Solutions is a veteran owned company whose focus is on providing tools for asset, user and work-flow management in a wide variety of business environments.

    rick@soaringsof tware.com

    System.Drawing. Printing.Invali dPrinterExcepti on was unhandled
    Message="Settin gs to access printer 'Samsung ML-2250 Series (Copy 1)' are
    not valid."
    Source="System. Drawing"
    StackTrace:
    at System.Drawing. Printing.Printe rSettings.GetHd evmodeInternal( )
    at System.Drawing. Printing.Printe rSettings.GetHd evmode(PageSett ings
    pageSettings)
    at System.Drawing. Printing.PrintC ontroller.OnSta rtPrint(PrintDo cument
    document, PrintEventArgs e)
    at
    System.Windows. Forms.PrintCont rollerWithStatu sDialog.OnStart Print(PrintDocu ment
    document, PrintEventArgs e)
    at System.Drawing. Printing.PrintC ontroller.Print (PrintDocument
    document)
    at System.Drawing. Printing.PrintD ocument.Print()
    at TCMaxLabelMaker .frmMain.cmdPri ntSequence_Clic k(Object sender,
    EventArgs e) in C:\VS2005\Copy (15) of
    TCMaxLabelMaker \TCMaxLabelMake r\frmMain.vb:li ne 4932
    at System.Windows. Forms.Control.O nClick(EventArg s e)
    at System.Windows. Forms.Button.On Click(EventArgs e)
    at System.Windows. Forms.Button.On MouseUp(MouseEv entArgs mevent)
    at System.Windows. Forms.Control.W mMouseUp(Messag e& m, MouseButtons
    button, Int32 clicks)
    at System.Windows. Forms.Control.W ndProc(Message& m)
    at System.Windows. Forms.ButtonBas e.WndProc(Messa ge& m)
    at System.Windows. Forms.Button.Wn dProc(Message& m)
    at
    System.Windows. Forms.Control.C ontrolNativeWin dow.OnMessage(M essage& m)
    at System.Windows. Forms.Control.C ontrolNativeWin dow.WndProc(Mes sage&
    m)
    at System.Windows. Forms.NativeWin dow.DebuggableC allback(IntPtr hWnd,
    Int32 msg, IntPtr wparam, IntPtr lparam)
    at System.Windows. Forms.UnsafeNat iveMethods.Disp atchMessageW(MS G&
    msg)
    at
    System.Windows. Forms.Applicati on.ComponentMan ager.System.Win dows.Forms.Unsa feNativeMethods .IMsoComponentM anager.FPushMes sageLoop(Int32
    dwComponentID, Int32 reason, Int32 pvLoopData)
    at
    System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo pInner(Int32
    reason, ApplicationCont ext context)
    at
    System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo p(Int32 reason,
    ApplicationCont ext context)
    at System.Windows. Forms.Applicati on.Run(Applicat ionContext context)
    at
    Microsoft.Visua lBasic.Applicat ionServices.Win dowsFormsApplic ationBase.OnRun ()
    at
    Microsoft.Visua lBasic.Applicat ionServices.Win dowsFormsApplic ationBase.DoApp licationModel()
    at
    Microsoft.Visua lBasic.Applicat ionServices.Win dowsFormsApplic ationBase.Run(S tring[]
    commandLine)
    at TCMaxLabelMaker .My.MyApplicati on.Main(String[] Args) in
    17d14f5c-a337-4978-8281-53493378c1071.v b:line 81
    at System.AppDomai n.nExecuteAssem bly(Assembly assembly, String[]
    args)
    at System.Runtime. Hosting.Manifes tRunner.Run(Boo lean checkAptModel)
    at System.Runtime. Hosting.Manifes tRunner.Execute AsAssembly()
    at
    System.Runtime. Hosting.Applica tionActivator.C reateInstance(A ctivationContex t
    activationConte xt, String[] activationCusto mData)
    at
    System.Runtime. Hosting.Applica tionActivator.C reateInstance(A ctivationContex t
    activationConte xt)
    at
    Microsoft.Visua lStudio.Hosting Process.HostPro c.RunUsersAssem blyDebugInZone( )
    at System.Threadin g.ThreadHelper. ThreadStart_Con text(Object state)
    at System.Threadin g.ExecutionCont ext.Run(Executi onContext
    executionContex t, ContextCallback callback, Object state)
    at System.Threadin g.ThreadHelper. ThreadStart()


  • Ken Tucker [MVP]

    #2
    RE: Printing second time fails

    Rick,

    I suspect the problem is in the printdocument's print event.
    Could you please post the code in that event.

    Ken
    ----------------

    "Rick Lederman" wrote:
    [color=blue]
    > I am using a PrintDocument and PrintDialog to print. The first time that I
    > print it works, but when I try to print a second time without exiting the
    > entire program I get an "InvalidPrinter Exception was unhandled" error. The
    > error happens in the third line below. The details of the error are below
    > my signature. Help?
    >
    > PrintDialog1.Pr interSettings.P rinterName = sLabelPrinterDe viceName
    >
    > PrintDialog1.Do cument = PrintDocument1
    >
    > PrintDialog1.Do cument.Print() ' the error happens in this line
    >
    >
    >
    > Any ideas?
    >
    > --
    > Rick Lederman
    > Soaring Software Solutions, Inc.
    > www.soaringsoftware.com
    > rick@soaringsof tware.com
    >
    > System.Drawing. Printing.Invali dPrinterExcepti on was unhandled
    > Message="Settin gs to access printer 'Samsung ML-2250 Series (Copy 1)' are
    > not valid."
    > Source="System. Drawing"
    > StackTrace:
    > at System.Drawing. Printing.Printe rSettings.GetHd evmodeInternal( )
    > at System.Drawing. Printing.Printe rSettings.GetHd evmode(PageSett ings
    > pageSettings)
    > at System.Drawing. Printing.PrintC ontroller.OnSta rtPrint(PrintDo cument
    > document, PrintEventArgs e)
    > at
    > System.Windows. Forms.PrintCont rollerWithStatu sDialog.OnStart Print(PrintDocu ment
    > document, PrintEventArgs e)
    > at System.Drawing. Printing.PrintC ontroller.Print (PrintDocument
    > document)
    > at System.Drawing. Printing.PrintD ocument.Print()
    > at TCMaxLabelMaker .frmMain.cmdPri ntSequence_Clic k(Object sender,
    > EventArgs e) in C:\VS2005\Copy (15) of
    > TCMaxLabelMaker \TCMaxLabelMake r\frmMain.vb:li ne 4932
    > at System.Windows. Forms.Control.O nClick(EventArg s e)
    > at System.Windows. Forms.Button.On Click(EventArgs e)
    > at System.Windows. Forms.Button.On MouseUp(MouseEv entArgs mevent)
    > at System.Windows. Forms.Control.W mMouseUp(Messag e& m, MouseButtons
    > button, Int32 clicks)
    > at System.Windows. Forms.Control.W ndProc(Message& m)
    > at System.Windows. Forms.ButtonBas e.WndProc(Messa ge& m)
    > at System.Windows. Forms.Button.Wn dProc(Message& m)
    > at
    > System.Windows. Forms.Control.C ontrolNativeWin dow.OnMessage(M essage& m)
    > at System.Windows. Forms.Control.C ontrolNativeWin dow.WndProc(Mes sage&
    > m)
    > at System.Windows. Forms.NativeWin dow.DebuggableC allback(IntPtr hWnd,
    > Int32 msg, IntPtr wparam, IntPtr lparam)
    > at System.Windows. Forms.UnsafeNat iveMethods.Disp atchMessageW(MS G&
    > msg)
    > at
    > System.Windows. Forms.Applicati on.ComponentMan ager.System.Win dows.Forms.Unsa feNativeMethods .IMsoComponentM anager.FPushMes sageLoop(Int32
    > dwComponentID, Int32 reason, Int32 pvLoopData)
    > at
    > System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo pInner(Int32
    > reason, ApplicationCont ext context)
    > at
    > System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo p(Int32 reason,
    > ApplicationCont ext context)
    > at System.Windows. Forms.Applicati on.Run(Applicat ionContext context)
    > at
    > Microsoft.Visua lBasic.Applicat ionServices.Win dowsFormsApplic ationBase.OnRun ()
    > at
    > Microsoft.Visua lBasic.Applicat ionServices.Win dowsFormsApplic ationBase.DoApp licationModel()
    > at
    > Microsoft.Visua lBasic.Applicat ionServices.Win dowsFormsApplic ationBase.Run(S tring[]
    > commandLine)
    > at TCMaxLabelMaker .My.MyApplicati on.Main(String[] Args) in
    > 17d14f5c-a337-4978-8281-53493378c1071.v b:line 81
    > at System.AppDomai n.nExecuteAssem bly(Assembly assembly, String[]
    > args)
    > at System.Runtime. Hosting.Manifes tRunner.Run(Boo lean checkAptModel)
    > at System.Runtime. Hosting.Manifes tRunner.Execute AsAssembly()
    > at
    > System.Runtime. Hosting.Applica tionActivator.C reateInstance(A ctivationContex t
    > activationConte xt, String[] activationCusto mData)
    > at
    > System.Runtime. Hosting.Applica tionActivator.C reateInstance(A ctivationContex t
    > activationConte xt)
    > at
    > Microsoft.Visua lStudio.Hosting Process.HostPro c.RunUsersAssem blyDebugInZone( )
    > at System.Threadin g.ThreadHelper. ThreadStart_Con text(Object state)
    > at System.Threadin g.ExecutionCont ext.Run(Executi onContext
    > executionContex t, ContextCallback callback, Object state)
    > at System.Threadin g.ThreadHelper. ThreadStart()
    >
    >
    >[/color]

    Comment

    • Rick Lederman

      #3
      Re: Printing second time fails

      Ken,

      Thanks for the help as I am at a loss. Here is the code:
      The code looses its format here ... should I post the code some other way?
      --
      Rick Lederman
      Soaring Software Solutions, Inc.

      Dim font As New Font("Times New Roman", CSng(txtFontSiz e.Text),
      FontStyle.Regul ar, GraphicsUnit.Po int)

      Dim TextWidth As Single

      Dim TextHeight As Single

      Dim AdjustedBarcode Scale As Single

      lCol = -1

      lRow = 1

      iX = dLeftMargin

      iY = dTopMargin

      iStart = iCurrent

      For iI = iStart To iEnd

      tdbLabels.Row = iI

      iCopies = CInt(tdbLabels. Columns(2).Valu e)

      For iJ = 1 To iCopies

      AdjustedBarcode Scale = BarcodeScale

      BarcodeProfessi onal1.Code = tdbLabels.Colum ns(0).Text.ToSt ring

      Dim BarcodeImage As Image = BarcodeProfessi onal1.GetBarcod eImage()

      Dim realBarcodeWidt h As Integer = BarcodeImage.Wi dth * BarcodeScale ' -
      BarcodeProfessi onal1.QuietZone Width * 2

      Dim realBarcodeHeig ht As Integer = BarcodeImage.He ight * BarcodeScale

      If realBarcodeWidt h > (dLabelWidth - dLabelWidth * 0.1) Then

      Dim MakeSmaller As Single

      MakeSmaller = (dLabelWidth - dLabelWidth * 0.1) / BarcodeImage.Wi dth

      AdjustedBarcode Scale = BarcodeScale * MakeSmaller

      realBarcodeWidt h = BarcodeImage.Wi dth * AdjustedBarcode Scale

      realBarcodeHeig ht = BarcodeImage.He ight * AdjustedBarcode Scale

      End If

      lCol = lCol + 1

      iCurrent = iI

      If lCol > lColumns - 1 Then

      iX = dLeftMargin + dLabelWidth / 2 - realBarcodeWidt h / 2 ' this does not
      work

      iY = iY + dDistanceBetwee nRows + dBarcodeHeight

      lRow = lRow + 1

      lCol = 0

      Else

      iX = dLeftMargin + dLabelWidth / 2 - realBarcodeWidt h / 2 + lCol *
      (dDistanceBetwe enColumns + dLabelWidth)

      End If

      If lRow > lRows Then

      e.HasMorePages = True

      Exit For

      Else

      e.HasMorePages = False

      End If

      Dim StringSizeTop As SizeF =
      e.Graphics.Meas ureString(txtMe ssage.Text.ToSt ring, font)

      TextWidth = StringSizeTop.W idth

      TextHeight = StringSizeTop.H eight

      e.Graphics.Draw String(txtMessa ge.Text.ToStrin g, font, Brushes.Black, New
      PointF(dLeftMar gin + dLabelWidth / 2 - TextWidth / 2 + lCol *
      (dDistanceBetwe enColumns + dLabelWidth), iY - TextHeight))

      sTemp.Remove(0, sTemp.Length)

      sTemp.Append(td bLabels.Columns (0).Text.ToStri ng & " " &
      tdbLabels.Colum ns(1).Text.ToSt ring)

      Dim StringSizeBotto m As SizeF = e.Graphics.Meas ureString(sTemp .ToString,
      font)

      TextWidth = StringSizeBotto m.Width

      TextHeight = StringSizeBotto m.Height

      e.Graphics.Draw String(sTemp.To String, font, Brushes.Black, New
      PointF(dLeftMar gin + dLabelWidth / 2 - TextWidth / 2 + lCol *
      (dDistanceBetwe enColumns + dLabelWidth), iY + realBarcodeHeig ht))

      BarcodeProfessi onal1.DrawOnCan vas(e.Graphics, New PointF(iX, iY),
      AdjustedBarcode Scale) ' this is in inches!

      Next iJ

      If e.HasMorePages = True Then

      Exit For

      End If

      Next iI


      Comment

      • Rick Lederman

        #4
        Re: Printing second time fails

        Ken,

        I just took ALL of the code out of the PrintDocument2_ PrintPage event and it
        feeds a page the first time that it is run and has the error the second
        time! So, it must not be the ocde in the PrintPage event?

        Private Sub PrintDocument2_ PrintPage(ByVal sender As Object, ByVal e As
        System.Drawing. Printing.PrintP ageEventArgs) Handles PrintDocument2. PrintPage



        Here is the code that I use in the Button_Click event (the end of the code
        anyway)

        If chkLandscape.Ch eckState = System.Windows. Forms.CheckStat e.Unchecked Then

        PrintDocument2. DefaultPageSett ings.Landscape = False

        Else

        PrintDocument2. DefaultPageSett ings.Landscape = True

        End If

        PrintDialog2.Pr interSettings.P rinterName = sLabelPrinterDe viceName ' I set
        this to the printer name very early in the program

        PrintDialog2.Do cument = PrintDocument2

        PrintDialog2.Do cument.Print() ' this line works the first time, and errors
        the second time. Then I must restart the program.


        --
        Rick Lederman
        Soaring Software Solutions, Inc.


        Comment

        • Ken Tucker [MVP]

          #5
          Re: Printing second time fails

          Rick,

          I see you are using a variable iCurrent to keep track of the
          record number. I do not see where you reset iCurrent to the begining of the
          list when you print the second time.

          Ken
          -------------------------

          "Rick Lederman" wrote:
          [color=blue]
          > Ken,
          >
          > I just took ALL of the code out of the PrintDocument2_ PrintPage event and it
          > feeds a page the first time that it is run and has the error the second
          > time! So, it must not be the ocde in the PrintPage event?
          >
          > Private Sub PrintDocument2_ PrintPage(ByVal sender As Object, ByVal e As
          > System.Drawing. Printing.PrintP ageEventArgs) Handles PrintDocument2. PrintPage
          >
          >
          >
          > Here is the code that I use in the Button_Click event (the end of the code
          > anyway)
          >
          > If chkLandscape.Ch eckState = System.Windows. Forms.CheckStat e.Unchecked Then
          >
          > PrintDocument2. DefaultPageSett ings.Landscape = False
          >
          > Else
          >
          > PrintDocument2. DefaultPageSett ings.Landscape = True
          >
          > End If
          >
          > PrintDialog2.Pr interSettings.P rinterName = sLabelPrinterDe viceName ' I set
          > this to the printer name very early in the program
          >
          > PrintDialog2.Do cument = PrintDocument2
          >
          > PrintDialog2.Do cument.Print() ' this line works the first time, and errors
          > the second time. Then I must restart the program.
          >
          >
          > --
          > Rick Lederman
          > Soaring Software Solutions, Inc.
          >
          >
          >[/color]

          Comment

          • Rick Lederman

            #6
            Re: Printing second time fails

            Ken,

            I reset it at the beginning of the CmdPrint_Click event. THat is the button
            that I click to do the print job. And, as I said, I deleted all of the code
            in the PrintDocument2_ PrintPage event and it still fails. Here is all of
            the code in the CmdPrint_Click event.

            Private Sub cmdPrint_Click( ByVal sender As System.Object, ByVal e As
            System.EventArg s) Handles cmdPrint.Click

            lCol = 0

            lRow = 0

            MyFlags.Printin gEmployees = False

            MyFlags.Printin gTools = True

            iStart = 0

            iCurrent = 0

            iEnd = CInt(tdbLabels. RowCount - 1)

            If iStart > iEnd Then

            MsgBox(MyLabels .IncorrectSeque nce, MsgBoxStyle.Inf ormation, "Sequence
            incorrect")

            Exit Sub

            End If

            iCopies = 1

            BarcodeProfessi onal1.AutoSize = True

            Select Case cmbBarcodeStyle .SelectedIndex

            Case Is = 0

            BarcodeProfessi onal1.Symbology = Symbology.Code3 9

            BarcodeScale = 1

            Case Is = 1

            BarcodeProfessi onal1.Symbology = Symbology.Code9 3

            BarcodeScale = 1

            Case Is = 2

            BarcodeProfessi onal1.Symbology = Symbology.DataM atrix

            BarcodeProfessi onal1.DataMatri xFormat = DataMatrixForma t.Auto

            BarcodeScale = CSng(txtCellSiz e.Text) / 14 * 0.39

            Case Is = 3

            BarcodeProfessi onal1.Symbology = Symbology.DataM atrix

            BarcodeProfessi onal1.DataMatri xFormat = DataMatrixForma t.C12X36

            BarcodeScale = CSng(txtCellSiz e.Text) / 14 * 0.39

            Case Is = 4

            BarcodeProfessi onal1.Symbology = Symbology.DataM atrix

            BarcodeProfessi onal1.DataMatri xFormat = DataMatrixForma t.C16X36

            BarcodeScale = CSng(txtCellSiz e.Text) / 14 * 0.39

            Case Is = 5

            BarcodeProfessi onal1.Symbology = Symbology.Code1 28

            BarcodeScale = 1

            Case Is = 6

            BarcodeProfessi onal1.Symbology = Symbology.Inter leaved2of5

            BarcodeScale = 1

            Case Is = 7

            BarcodeProfessi onal1.Symbology = Symbology.Pdf41 7

            BarcodeScale = 1

            End Select

            BarcodeProfessi onal1.DataMatri xModuleSize = 4 ' CInt(txtCellSiz e.Text) - 10

            dBarcodeHeight = CSng(cZero((txt BarcodeHeight.T ext) * 100))

            dBarcodeWidth = CSng(cZero(txtB arcodeWidth.Tex t) * 100)

            BarcodeProfessi onal1.BarHeight = dBarcodeHeight

            BarcodeProfessi onal1.DisplayCo de = False

            dLabelHeight = CSng(txtBarcode Height.Text) * 100

            dLabelWidth = CSng(txtLabelWi dth.Text) * 100

            lColumns = CInt(txtNumberO fColumns.Text)

            lRows = CInt(txtNumberO fRows.Text)

            dLeftMargin = CSng(txtLeftMar gin.Text) * 100

            dTopMargin = CSng(txtTopMarg in.Text) * 100

            dDistanceBetwee nRows = CSng(txtRowDist ance.Text) * 100

            dDistanceBetwee nColumns = CSng(txtColumnD istance.Text) * 100

            If chkLandscape.Ch eckState = System.Windows. Forms.CheckStat e.Unchecked Then

            PrintDocument2. DefaultPageSett ings.Landscape = False

            Else

            PrintDocument2. DefaultPageSett ings.Landscape = True

            End If

            PrintDialog2.Pr interSettings.P rinterName = sLabelPrinterDe viceName

            PrintDialog2.Do cument = PrintDocument2

            PrintDialog2.Do cument.Print()



            End Sub


            --
            Rick Lederman
            Soaring Software Solutions, Inc.
            Soaring Software Solutions is a veteran owned company whose focus is on providing tools for asset, user and work-flow management in a wide variety of business environments.

            rick@soaringsof tware.com

            "Ken Tucker [MVP]" <KenTuckerMVP@d iscussions.micr osoft.com> wrote in message
            news:40326F8A-4F01-4260-A732-070A0E5B1FAE@mi crosoft.com...[color=blue]
            > Rick,
            >
            > I see you are using a variable iCurrent to keep track of the
            > record number. I do not see where you reset iCurrent to the begining of
            > the
            > list when you print the second time.
            >
            > Ken
            > -------------------------
            >
            > "Rick Lederman" wrote:
            >[color=green]
            >> Ken,
            >>
            >> I just took ALL of the code out of the PrintDocument2_ PrintPage event and
            >> it
            >> feeds a page the first time that it is run and has the error the second
            >> time! So, it must not be the ocde in the PrintPage event?
            >>
            >> Private Sub PrintDocument2_ PrintPage(ByVal sender As Object, ByVal e As
            >> System.Drawing. Printing.PrintP ageEventArgs) Handles
            >> PrintDocument2. PrintPage
            >>
            >>
            >>
            >> Here is the code that I use in the Button_Click event (the end of the
            >> code
            >> anyway)
            >>
            >> If chkLandscape.Ch eckState = System.Windows. Forms.CheckStat e.Unchecked
            >> Then
            >>
            >> PrintDocument2. DefaultPageSett ings.Landscape = False
            >>
            >> Else
            >>
            >> PrintDocument2. DefaultPageSett ings.Landscape = True
            >>
            >> End If
            >>
            >> PrintDialog2.Pr interSettings.P rinterName = sLabelPrinterDe viceName ' I
            >> set
            >> this to the printer name very early in the program
            >>
            >> PrintDialog2.Do cument = PrintDocument2
            >>
            >> PrintDialog2.Do cument.Print() ' this line works the first time, and
            >> errors
            >> the second time. Then I must restart the program.
            >>
            >>
            >> --
            >> Rick Lederman
            >> Soaring Software Solutions, Inc.
            >>
            >>
            >>[/color][/color]


            Comment

            • Ken Tucker [MVP]

              #7
              Re: Printing second time fails

              Rick,

              Instead of PrintDialog2.Do cument.Print() try printdocument2. print

              Ken
              --------------------

              "Rick Lederman" wrote:
              [color=blue]
              > Ken,
              >
              > I reset it at the beginning of the CmdPrint_Click event. THat is the button
              > that I click to do the print job. And, as I said, I deleted all of the code
              > in the PrintDocument2_ PrintPage event and it still fails. Here is all of
              > the code in the CmdPrint_Click event.
              >
              > Private Sub cmdPrint_Click( ByVal sender As System.Object, ByVal e As
              > System.EventArg s) Handles cmdPrint.Click
              >
              > lCol = 0
              >
              > lRow = 0
              >
              > MyFlags.Printin gEmployees = False
              >
              > MyFlags.Printin gTools = True
              >
              > iStart = 0
              >
              > iCurrent = 0
              >
              > iEnd = CInt(tdbLabels. RowCount - 1)
              >
              > If iStart > iEnd Then
              >
              > MsgBox(MyLabels .IncorrectSeque nce, MsgBoxStyle.Inf ormation, "Sequence
              > incorrect")
              >
              > Exit Sub
              >
              > End If
              >
              > iCopies = 1
              >
              > BarcodeProfessi onal1.AutoSize = True
              >
              > Select Case cmbBarcodeStyle .SelectedIndex
              >
              > Case Is = 0
              >
              > BarcodeProfessi onal1.Symbology = Symbology.Code3 9
              >
              > BarcodeScale = 1
              >
              > Case Is = 1
              >
              > BarcodeProfessi onal1.Symbology = Symbology.Code9 3
              >
              > BarcodeScale = 1
              >
              > Case Is = 2
              >
              > BarcodeProfessi onal1.Symbology = Symbology.DataM atrix
              >
              > BarcodeProfessi onal1.DataMatri xFormat = DataMatrixForma t.Auto
              >
              > BarcodeScale = CSng(txtCellSiz e.Text) / 14 * 0.39
              >
              > Case Is = 3
              >
              > BarcodeProfessi onal1.Symbology = Symbology.DataM atrix
              >
              > BarcodeProfessi onal1.DataMatri xFormat = DataMatrixForma t.C12X36
              >
              > BarcodeScale = CSng(txtCellSiz e.Text) / 14 * 0.39
              >
              > Case Is = 4
              >
              > BarcodeProfessi onal1.Symbology = Symbology.DataM atrix
              >
              > BarcodeProfessi onal1.DataMatri xFormat = DataMatrixForma t.C16X36
              >
              > BarcodeScale = CSng(txtCellSiz e.Text) / 14 * 0.39
              >
              > Case Is = 5
              >
              > BarcodeProfessi onal1.Symbology = Symbology.Code1 28
              >
              > BarcodeScale = 1
              >
              > Case Is = 6
              >
              > BarcodeProfessi onal1.Symbology = Symbology.Inter leaved2of5
              >
              > BarcodeScale = 1
              >
              > Case Is = 7
              >
              > BarcodeProfessi onal1.Symbology = Symbology.Pdf41 7
              >
              > BarcodeScale = 1
              >
              > End Select
              >
              > BarcodeProfessi onal1.DataMatri xModuleSize = 4 ' CInt(txtCellSiz e.Text) - 10
              >
              > dBarcodeHeight = CSng(cZero((txt BarcodeHeight.T ext) * 100))
              >
              > dBarcodeWidth = CSng(cZero(txtB arcodeWidth.Tex t) * 100)
              >
              > BarcodeProfessi onal1.BarHeight = dBarcodeHeight
              >
              > BarcodeProfessi onal1.DisplayCo de = False
              >
              > dLabelHeight = CSng(txtBarcode Height.Text) * 100
              >
              > dLabelWidth = CSng(txtLabelWi dth.Text) * 100
              >
              > lColumns = CInt(txtNumberO fColumns.Text)
              >
              > lRows = CInt(txtNumberO fRows.Text)
              >
              > dLeftMargin = CSng(txtLeftMar gin.Text) * 100
              >
              > dTopMargin = CSng(txtTopMarg in.Text) * 100
              >
              > dDistanceBetwee nRows = CSng(txtRowDist ance.Text) * 100
              >
              > dDistanceBetwee nColumns = CSng(txtColumnD istance.Text) * 100
              >
              > If chkLandscape.Ch eckState = System.Windows. Forms.CheckStat e.Unchecked Then
              >
              > PrintDocument2. DefaultPageSett ings.Landscape = False
              >
              > Else
              >
              > PrintDocument2. DefaultPageSett ings.Landscape = True
              >
              > End If
              >
              > PrintDialog2.Pr interSettings.P rinterName = sLabelPrinterDe viceName
              >
              > PrintDialog2.Do cument = PrintDocument2
              >
              > PrintDialog2.Do cument.Print()
              >
              >
              >
              > End Sub
              >
              >
              > --
              > Rick Lederman
              > Soaring Software Solutions, Inc.
              > www.soaringsoftware.com
              > rick@soaringsof tware.com
              >
              > "Ken Tucker [MVP]" <KenTuckerMVP@d iscussions.micr osoft.com> wrote in message
              > news:40326F8A-4F01-4260-A732-070A0E5B1FAE@mi crosoft.com...[color=green]
              > > Rick,
              > >
              > > I see you are using a variable iCurrent to keep track of the
              > > record number. I do not see where you reset iCurrent to the begining of
              > > the
              > > list when you print the second time.
              > >
              > > Ken
              > > -------------------------
              > >
              > > "Rick Lederman" wrote:
              > >[color=darkred]
              > >> Ken,
              > >>
              > >> I just took ALL of the code out of the PrintDocument2_ PrintPage event and
              > >> it
              > >> feeds a page the first time that it is run and has the error the second
              > >> time! So, it must not be the ocde in the PrintPage event?
              > >>
              > >> Private Sub PrintDocument2_ PrintPage(ByVal sender As Object, ByVal e As
              > >> System.Drawing. Printing.PrintP ageEventArgs) Handles
              > >> PrintDocument2. PrintPage
              > >>
              > >>
              > >>
              > >> Here is the code that I use in the Button_Click event (the end of the
              > >> code
              > >> anyway)
              > >>
              > >> If chkLandscape.Ch eckState = System.Windows. Forms.CheckStat e.Unchecked
              > >> Then
              > >>
              > >> PrintDocument2. DefaultPageSett ings.Landscape = False
              > >>
              > >> Else
              > >>
              > >> PrintDocument2. DefaultPageSett ings.Landscape = True
              > >>
              > >> End If
              > >>
              > >> PrintDialog2.Pr interSettings.P rinterName = sLabelPrinterDe viceName ' I
              > >> set
              > >> this to the printer name very early in the program
              > >>
              > >> PrintDialog2.Do cument = PrintDocument2
              > >>
              > >> PrintDialog2.Do cument.Print() ' this line works the first time, and
              > >> errors
              > >> the second time. Then I must restart the program.
              > >>
              > >>
              > >> --
              > >> Rick Lederman
              > >> Soaring Software Solutions, Inc.
              > >>
              > >>
              > >>[/color][/color]
              >
              >
              >[/color]

              Comment

              • Rick Lederman

                #8
                Re: Printing second time fails

                Again, does not work. That is strange, the first thime that I print it
                everything works. Click the print button again and I get the same
                "InvalidPrinter Exception was unhandled" error. Underneigh that it also says
                (same as before) " Settings to access printer 'Samsung ML-2250 'are not
                valid." ...

                --
                Rick Lederman
                Soaring Software Solutions, Inc.
                Soaring Software Solutions is a veteran owned company whose focus is on providing tools for asset, user and work-flow management in a wide variety of business environments.

                rick@soaringsof tware.com

                "Ken Tucker [MVP]" <KenTuckerMVP@d iscussions.micr osoft.com> wrote in message
                news:E245590E-B0B4-4DE7-BBED-CA97F3F2DBA3@mi crosoft.com...[color=blue]
                > Rick,
                >
                > Instead of PrintDialog2.Do cument.Print() try printdocument2. print
                >
                > Ken
                > --------------------
                >
                > "Rick Lederman" wrote:
                >[color=green]
                >> Ken,
                >>
                >> I reset it at the beginning of the CmdPrint_Click event. THat is the
                >> button
                >> that I click to do the print job. And, as I said, I deleted all of the
                >> code
                >> in the PrintDocument2_ PrintPage event and it still fails. Here is all of
                >> the code in the CmdPrint_Click event.
                >>
                >> Private Sub cmdPrint_Click( ByVal sender As System.Object, ByVal e As
                >> System.EventArg s) Handles cmdPrint.Click
                >>
                >> lCol = 0
                >>
                >> lRow = 0
                >>
                >> MyFlags.Printin gEmployees = False
                >>
                >> MyFlags.Printin gTools = True
                >>
                >> iStart = 0
                >>
                >> iCurrent = 0
                >>
                >> iEnd = CInt(tdbLabels. RowCount - 1)
                >>
                >> If iStart > iEnd Then
                >>
                >> MsgBox(MyLabels .IncorrectSeque nce, MsgBoxStyle.Inf ormation, "Sequence
                >> incorrect")
                >>
                >> Exit Sub
                >>
                >> End If
                >>
                >> iCopies = 1
                >>
                >> BarcodeProfessi onal1.AutoSize = True
                >>
                >> Select Case cmbBarcodeStyle .SelectedIndex
                >>
                >> Case Is = 0
                >>
                >> BarcodeProfessi onal1.Symbology = Symbology.Code3 9
                >>
                >> BarcodeScale = 1
                >>
                >> Case Is = 1
                >>
                >> BarcodeProfessi onal1.Symbology = Symbology.Code9 3
                >>
                >> BarcodeScale = 1
                >>
                >> Case Is = 2
                >>
                >> BarcodeProfessi onal1.Symbology = Symbology.DataM atrix
                >>
                >> BarcodeProfessi onal1.DataMatri xFormat = DataMatrixForma t.Auto
                >>
                >> BarcodeScale = CSng(txtCellSiz e.Text) / 14 * 0.39
                >>
                >> Case Is = 3
                >>
                >> BarcodeProfessi onal1.Symbology = Symbology.DataM atrix
                >>
                >> BarcodeProfessi onal1.DataMatri xFormat = DataMatrixForma t.C12X36
                >>
                >> BarcodeScale = CSng(txtCellSiz e.Text) / 14 * 0.39
                >>
                >> Case Is = 4
                >>
                >> BarcodeProfessi onal1.Symbology = Symbology.DataM atrix
                >>
                >> BarcodeProfessi onal1.DataMatri xFormat = DataMatrixForma t.C16X36
                >>
                >> BarcodeScale = CSng(txtCellSiz e.Text) / 14 * 0.39
                >>
                >> Case Is = 5
                >>
                >> BarcodeProfessi onal1.Symbology = Symbology.Code1 28
                >>
                >> BarcodeScale = 1
                >>
                >> Case Is = 6
                >>
                >> BarcodeProfessi onal1.Symbology = Symbology.Inter leaved2of5
                >>
                >> BarcodeScale = 1
                >>
                >> Case Is = 7
                >>
                >> BarcodeProfessi onal1.Symbology = Symbology.Pdf41 7
                >>
                >> BarcodeScale = 1
                >>
                >> End Select
                >>
                >> BarcodeProfessi onal1.DataMatri xModuleSize = 4 ' CInt(txtCellSiz e.Text) -
                >> 10
                >>
                >> dBarcodeHeight = CSng(cZero((txt BarcodeHeight.T ext) * 100))
                >>
                >> dBarcodeWidth = CSng(cZero(txtB arcodeWidth.Tex t) * 100)
                >>
                >> BarcodeProfessi onal1.BarHeight = dBarcodeHeight
                >>
                >> BarcodeProfessi onal1.DisplayCo de = False
                >>
                >> dLabelHeight = CSng(txtBarcode Height.Text) * 100
                >>
                >> dLabelWidth = CSng(txtLabelWi dth.Text) * 100
                >>
                >> lColumns = CInt(txtNumberO fColumns.Text)
                >>
                >> lRows = CInt(txtNumberO fRows.Text)
                >>
                >> dLeftMargin = CSng(txtLeftMar gin.Text) * 100
                >>
                >> dTopMargin = CSng(txtTopMarg in.Text) * 100
                >>
                >> dDistanceBetwee nRows = CSng(txtRowDist ance.Text) * 100
                >>
                >> dDistanceBetwee nColumns = CSng(txtColumnD istance.Text) * 100
                >>
                >> If chkLandscape.Ch eckState = System.Windows. Forms.CheckStat e.Unchecked
                >> Then
                >>
                >> PrintDocument2. DefaultPageSett ings.Landscape = False
                >>
                >> Else
                >>
                >> PrintDocument2. DefaultPageSett ings.Landscape = True
                >>
                >> End If
                >>
                >> PrintDialog2.Pr interSettings.P rinterName = sLabelPrinterDe viceName
                >>
                >> PrintDialog2.Do cument = PrintDocument2
                >>
                >> PrintDialog2.Do cument.Print()
                >>
                >>
                >>
                >> End Sub
                >>
                >>
                >> --
                >> Rick Lederman
                >> Soaring Software Solutions, Inc.
                >> www.soaringsoftware.com
                >> rick@soaringsof tware.com
                >>
                >> "Ken Tucker [MVP]" <KenTuckerMVP@d iscussions.micr osoft.com> wrote in
                >> message
                >> news:40326F8A-4F01-4260-A732-070A0E5B1FAE@mi crosoft.com...[color=darkred]
                >> > Rick,
                >> >
                >> > I see you are using a variable iCurrent to keep track of the
                >> > record number. I do not see where you reset iCurrent to the begining
                >> > of
                >> > the
                >> > list when you print the second time.
                >> >
                >> > Ken
                >> > -------------------------
                >> >
                >> > "Rick Lederman" wrote:
                >> >
                >> >> Ken,
                >> >>
                >> >> I just took ALL of the code out of the PrintDocument2_ PrintPage event
                >> >> and
                >> >> it
                >> >> feeds a page the first time that it is run and has the error the
                >> >> second
                >> >> time! So, it must not be the ocde in the PrintPage event?
                >> >>
                >> >> Private Sub PrintDocument2_ PrintPage(ByVal sender As Object, ByVal e
                >> >> As
                >> >> System.Drawing. Printing.PrintP ageEventArgs) Handles
                >> >> PrintDocument2. PrintPage
                >> >>
                >> >>
                >> >>
                >> >> Here is the code that I use in the Button_Click event (the end of the
                >> >> code
                >> >> anyway)
                >> >>
                >> >> If chkLandscape.Ch eckState = System.Windows. Forms.CheckStat e.Unchecked
                >> >> Then
                >> >>
                >> >> PrintDocument2. DefaultPageSett ings.Landscape = False
                >> >>
                >> >> Else
                >> >>
                >> >> PrintDocument2. DefaultPageSett ings.Landscape = True
                >> >>
                >> >> End If
                >> >>
                >> >> PrintDialog2.Pr interSettings.P rinterName = sLabelPrinterDe viceName '
                >> >> I
                >> >> set
                >> >> this to the printer name very early in the program
                >> >>
                >> >> PrintDialog2.Do cument = PrintDocument2
                >> >>
                >> >> PrintDialog2.Do cument.Print() ' this line works the first time, and
                >> >> errors
                >> >> the second time. Then I must restart the program.
                >> >>
                >> >>
                >> >> --
                >> >> Rick Lederman
                >> >> Soaring Software Solutions, Inc.
                >> >>
                >> >>
                >> >>[/color]
                >>
                >>
                >>[/color][/color]


                Comment

                • Rick Lederman

                  #9
                  Re: Printing second time fails (NO LONGER)

                  To test things I put the following into the program

                  If PrintDialog2.Pr interSettings.I sValid = True Then

                  PrintDialog2.Do cument.Print() ' this was already there

                  End If

                  And, imagine that the IsValid returns False on the second print job. So the
                  question remains what makes the PrinterSettings become false after using it
                  once?

                  And, during a program run, I set the printer to a different printer, and the
                  first time that it ran it printed OK, the second time that I tried to print,
                  IT RETURNED TRUE and ran OK! And it continues to work for the new printer.

                  So, I change the printer selector back to the original printer. And it
                  WORKS ... these kinds of problems I really don't need, but for now it is all
                  WORKING ...

                  Ken, thanks for your help. I have no idea what was going on within this PC
                  but simply printing to a different printer then switching back to this
                  printer seems to have fixed it. The magic of Windows!

                  --
                  Rick Lederman
                  Soaring Software Solutions, Inc.
                  Soaring Software Solutions is a veteran owned company whose focus is on providing tools for asset, user and work-flow management in a wide variety of business environments.

                  rick@soaringsof tware.com

                  "Ken Tucker [MVP]" <KenTuckerMVP@d iscussions.micr osoft.com> wrote in message
                  news:E245590E-B0B4-4DE7-BBED-CA97F3F2DBA3@mi crosoft.com...[color=blue]
                  > Rick,
                  >
                  > Instead of PrintDialog2.Do cument.Print() try printdocument2. print
                  >
                  > Ken
                  > --------------------
                  >
                  > "Rick Lederman" wrote:
                  >[color=green]
                  >> Ken,
                  >>
                  >> I reset it at the beginning of the CmdPrint_Click event. THat is the
                  >> button
                  >> that I click to do the print job. And, as I said, I deleted all of the
                  >> code
                  >> in the PrintDocument2_ PrintPage event and it still fails. Here is all of
                  >> the code in the CmdPrint_Click event.
                  >>
                  >> Private Sub cmdPrint_Click( ByVal sender As System.Object, ByVal e As
                  >> System.EventArg s) Handles cmdPrint.Click
                  >>
                  >> lCol = 0
                  >>
                  >> lRow = 0
                  >>
                  >> MyFlags.Printin gEmployees = False
                  >>
                  >> MyFlags.Printin gTools = True
                  >>
                  >> iStart = 0
                  >>
                  >> iCurrent = 0
                  >>
                  >> iEnd = CInt(tdbLabels. RowCount - 1)
                  >>
                  >> If iStart > iEnd Then
                  >>
                  >> MsgBox(MyLabels .IncorrectSeque nce, MsgBoxStyle.Inf ormation, "Sequence
                  >> incorrect")
                  >>
                  >> Exit Sub
                  >>
                  >> End If
                  >>
                  >> iCopies = 1
                  >>
                  >> BarcodeProfessi onal1.AutoSize = True
                  >>
                  >> Select Case cmbBarcodeStyle .SelectedIndex
                  >>
                  >> Case Is = 0
                  >>
                  >> BarcodeProfessi onal1.Symbology = Symbology.Code3 9
                  >>
                  >> BarcodeScale = 1
                  >>
                  >> Case Is = 1
                  >>
                  >> BarcodeProfessi onal1.Symbology = Symbology.Code9 3
                  >>
                  >> BarcodeScale = 1
                  >>
                  >> Case Is = 2
                  >>
                  >> BarcodeProfessi onal1.Symbology = Symbology.DataM atrix
                  >>
                  >> BarcodeProfessi onal1.DataMatri xFormat = DataMatrixForma t.Auto
                  >>
                  >> BarcodeScale = CSng(txtCellSiz e.Text) / 14 * 0.39
                  >>
                  >> Case Is = 3
                  >>
                  >> BarcodeProfessi onal1.Symbology = Symbology.DataM atrix
                  >>
                  >> BarcodeProfessi onal1.DataMatri xFormat = DataMatrixForma t.C12X36
                  >>
                  >> BarcodeScale = CSng(txtCellSiz e.Text) / 14 * 0.39
                  >>
                  >> Case Is = 4
                  >>
                  >> BarcodeProfessi onal1.Symbology = Symbology.DataM atrix
                  >>
                  >> BarcodeProfessi onal1.DataMatri xFormat = DataMatrixForma t.C16X36
                  >>
                  >> BarcodeScale = CSng(txtCellSiz e.Text) / 14 * 0.39
                  >>
                  >> Case Is = 5
                  >>
                  >> BarcodeProfessi onal1.Symbology = Symbology.Code1 28
                  >>
                  >> BarcodeScale = 1
                  >>
                  >> Case Is = 6
                  >>
                  >> BarcodeProfessi onal1.Symbology = Symbology.Inter leaved2of5
                  >>
                  >> BarcodeScale = 1
                  >>
                  >> Case Is = 7
                  >>
                  >> BarcodeProfessi onal1.Symbology = Symbology.Pdf41 7
                  >>
                  >> BarcodeScale = 1
                  >>
                  >> End Select
                  >>
                  >> BarcodeProfessi onal1.DataMatri xModuleSize = 4 ' CInt(txtCellSiz e.Text) -
                  >> 10
                  >>
                  >> dBarcodeHeight = CSng(cZero((txt BarcodeHeight.T ext) * 100))
                  >>
                  >> dBarcodeWidth = CSng(cZero(txtB arcodeWidth.Tex t) * 100)
                  >>
                  >> BarcodeProfessi onal1.BarHeight = dBarcodeHeight
                  >>
                  >> BarcodeProfessi onal1.DisplayCo de = False
                  >>
                  >> dLabelHeight = CSng(txtBarcode Height.Text) * 100
                  >>
                  >> dLabelWidth = CSng(txtLabelWi dth.Text) * 100
                  >>
                  >> lColumns = CInt(txtNumberO fColumns.Text)
                  >>
                  >> lRows = CInt(txtNumberO fRows.Text)
                  >>
                  >> dLeftMargin = CSng(txtLeftMar gin.Text) * 100
                  >>
                  >> dTopMargin = CSng(txtTopMarg in.Text) * 100
                  >>
                  >> dDistanceBetwee nRows = CSng(txtRowDist ance.Text) * 100
                  >>
                  >> dDistanceBetwee nColumns = CSng(txtColumnD istance.Text) * 100
                  >>
                  >> If chkLandscape.Ch eckState = System.Windows. Forms.CheckStat e.Unchecked
                  >> Then
                  >>
                  >> PrintDocument2. DefaultPageSett ings.Landscape = False
                  >>
                  >> Else
                  >>
                  >> PrintDocument2. DefaultPageSett ings.Landscape = True
                  >>
                  >> End If
                  >>
                  >> PrintDialog2.Pr interSettings.P rinterName = sLabelPrinterDe viceName
                  >>
                  >> PrintDialog2.Do cument = PrintDocument2
                  >>
                  >> PrintDialog2.Do cument.Print()
                  >>
                  >>
                  >>
                  >> End Sub
                  >>
                  >>
                  >> --
                  >> Rick Lederman
                  >> Soaring Software Solutions, Inc.
                  >> www.soaringsoftware.com
                  >> rick@soaringsof tware.com
                  >>
                  >> "Ken Tucker [MVP]" <KenTuckerMVP@d iscussions.micr osoft.com> wrote in
                  >> message
                  >> news:40326F8A-4F01-4260-A732-070A0E5B1FAE@mi crosoft.com...[color=darkred]
                  >> > Rick,
                  >> >
                  >> > I see you are using a variable iCurrent to keep track of the
                  >> > record number. I do not see where you reset iCurrent to the begining
                  >> > of
                  >> > the
                  >> > list when you print the second time.
                  >> >
                  >> > Ken
                  >> > -------------------------
                  >> >
                  >> > "Rick Lederman" wrote:
                  >> >
                  >> >> Ken,
                  >> >>
                  >> >> I just took ALL of the code out of the PrintDocument2_ PrintPage event
                  >> >> and
                  >> >> it
                  >> >> feeds a page the first time that it is run and has the error the
                  >> >> second
                  >> >> time! So, it must not be the ocde in the PrintPage event?
                  >> >>
                  >> >> Private Sub PrintDocument2_ PrintPage(ByVal sender As Object, ByVal e
                  >> >> As
                  >> >> System.Drawing. Printing.PrintP ageEventArgs) Handles
                  >> >> PrintDocument2. PrintPage
                  >> >>
                  >> >>
                  >> >>
                  >> >> Here is the code that I use in the Button_Click event (the end of the
                  >> >> code
                  >> >> anyway)
                  >> >>
                  >> >> If chkLandscape.Ch eckState = System.Windows. Forms.CheckStat e.Unchecked
                  >> >> Then
                  >> >>
                  >> >> PrintDocument2. DefaultPageSett ings.Landscape = False
                  >> >>
                  >> >> Else
                  >> >>
                  >> >> PrintDocument2. DefaultPageSett ings.Landscape = True
                  >> >>
                  >> >> End If
                  >> >>
                  >> >> PrintDialog2.Pr interSettings.P rinterName = sLabelPrinterDe viceName '
                  >> >> I
                  >> >> set
                  >> >> this to the printer name very early in the program
                  >> >>
                  >> >> PrintDialog2.Do cument = PrintDocument2
                  >> >>
                  >> >> PrintDialog2.Do cument.Print() ' this line works the first time, and
                  >> >> errors
                  >> >> the second time. Then I must restart the program.
                  >> >>
                  >> >>
                  >> >> --
                  >> >> Rick Lederman
                  >> >> Soaring Software Solutions, Inc.
                  >> >>
                  >> >>
                  >> >>[/color]
                  >>
                  >>
                  >>[/color][/color]


                  Comment

                  Working...