Printing from a Database in VB 2005 Express

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Fenris54
    New Member
    • Mar 2007
    • 5

    Printing from a Database in VB 2005 Express

    Hi,
    I have an Access database in my program that holds names and room numbers. They are meant to go on those Avery label stickers but I am not sure how to get the data into a form that I can manipulate into the proper format. I'm not sure what else to say/ include.
    Thanks in advance.
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    #2
    Hello there, Fenris54!

    I hate to do this to you. You are hoping for a great response, I'm sure. But would you mind posting what you have working thus far, so one can have a closer look? I will be honest in saying I ahve not yet tackled VB Express. Knowledgeable and helpful members here will see your post and will assist if something is posted. How's that for a deal?

    Good luck with the project!

    Dököll

    Comment

    • Fenris54
      New Member
      • Mar 2007
      • 5

      #3
      No problem. I wasn't sure if it would be needed. But this is what I have. I basically have 2 forms. One is for adding, deleting, and viewing the database and the other is for printing. There are 30 buttons (Just like the avery label stickers) that when you click on it, it would make sure that when the label printed the printer would skip over that label space. (So you aren't printing over blank labels.)

      I apologize for the lack of comments. I always comment after I finish coding.

      Code for form1
      Code:
      Public Class frmLabelPrinter
      
          Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
              'TODO: This line of code loads data into the 'LabelPrinterDS.tblEmployees' table. You can move, or remove it, as needed.
              Me.TblEmployeesTableAdapter.Fill(Me.LabelPrinterDS.tblEmployees)
      
          End Sub
      
          Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
              End
          End Sub
      
          Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
              Try
                  If chkAttending.Checked = True Then
                      TblEmployeesTableAdapter.Insert(txtFirstName.Text, txtLastName.Text, txtRoomNum.Text, True)
                      Me.TblEmployeesTableAdapter.Fill(Me.LabelPrinterDS.tblEmployees)
                  End If
                  If chkAttending.Checked = False Then
                      TblEmployeesTableAdapter.Insert(txtFirstName.Text, txtLastName.Text, txtRoomNum.Text, False)
                      Me.TblEmployeesTableAdapter.Fill(Me.LabelPrinterDS.tblEmployees)
                  End If
              Catch ex As Exception
                  MessageBox.Show(ex.Message, "Data Input Error")
              End Try
      
              txtFirstName.Clear()
              txtLastName.Clear()
              txtRoomNum.Clear()
              chkAttending.Checked = True
              txtFirstName.Focus()
          End Sub
      
          Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
              Dim IDNum As Integer = txtID.Text
              Dim row As DataRow = LabelPrinterDS.tblEmployees.FindByID(IDNum)
              LabelPrinterDS.tblEmployees.Rows.Remove(row)
      
              txtID.Clear()
              txtID.Focus()
          End Sub
      
          Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
              My.Forms.frmPrinting.Show()
          End Sub
      
          Private Sub txtFirstName_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtFirstName.GotFocus, txtLastName.GotFocus, txtRoomNum.GotFocus, txtID.GotFocus
              sender.Backcolor = Color.LemonChiffon
          End Sub
      
          Private Sub txtFirstName_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtFirstName.KeyPress
              If e.KeyChar = Chr(Keys.Enter) Then
                  txtLastName.Focus()
              End If
          End Sub
      
          Private Sub txtLastName_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtLastName.KeyPress
              If e.KeyChar = Chr(Keys.Enter) Then
                  txtRoomNum.Focus()
              End If
          End Sub
      
          Private Sub txtRoomNum_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtRoomNum.KeyPress
              If e.KeyChar = Chr(Keys.Enter) Then
                  chkAttending.Focus()
              End If
          End Sub
      
          Private Sub txtID_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtID.KeyPress
              If e.KeyChar = Chr(Keys.Enter) Then
                  btnDelete.Focus()
              End If
          End Sub
      
          Private Sub txtFirstName_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtFirstName.LostFocus, txtLastName.LostFocus, txtRoomNum.LostFocus, txtID.LostFocus
              sender.BackColor = Color.White
          End Sub
      
          Private Sub chkAttending_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles chkAttending.KeyPress
              If e.KeyChar = Chr(Keys.Enter) Then
                  btnAdd.Focus()
              End If
          End Sub
      End Class
      Code for form 2 (I haven't written the code for the buttons yet, I am working on the math for spacing.
      Code:
      Public Class frmPrinting
      
          Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
              End
          End Sub
      
          Private Sub btnBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
              My.Forms.frmLabelPrinter.Show()
          End Sub
      
          Private Sub btnPrintPreview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrintPreview.Click
              ppdDialog.ShowDialog()
          End Sub
      
          Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
              pdDocument.Print()
          End Sub
      
      End Class

      Comment

      • Dököll
        Recognized Expert Top Contributor
        • Nov 2006
        • 2379

        #4
        Originally posted by Fenris54
        No problem. I wasn't sure if it would be needed. But this is what I have. I basically have 2 forms. One is for adding, deleting, and viewing the database and the other is for printing. There are 30 buttons (Just like the avery label stickers) that when you click on it, it would make sure that when the label printed the printer would skip over that label space. (So you aren't printing over blank labels.)

        I apologize for the lack of comments. I always comment after I finish coding.

        Code for form1
        Code:
        Public Class frmLabelPrinter
        
            Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
                'TODO: This line of code loads data into the 'LabelPrinterDS.tblEmployees' table. You can move, or remove it, as needed.
                Me.TblEmployeesTableAdapter.Fill(Me.LabelPrinterDS.tblEmployees)
        
            End Sub
        
            Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
                End
            End Sub
        
            Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
                Try
                    If chkAttending.Checked = True Then
                        TblEmployeesTableAdapter.Insert(txtFirstName.Text, txtLastName.Text, txtRoomNum.Text, True)
                        Me.TblEmployeesTableAdapter.Fill(Me.LabelPrinterDS.tblEmployees)
                    End If
                    If chkAttending.Checked = False Then
                        TblEmployeesTableAdapter.Insert(txtFirstName.Text, txtLastName.Text, txtRoomNum.Text, False)
                        Me.TblEmployeesTableAdapter.Fill(Me.LabelPrinterDS.tblEmployees)
                    End If
                Catch ex As Exception
                    MessageBox.Show(ex.Message, "Data Input Error")
                End Try
        
                txtFirstName.Clear()
                txtLastName.Clear()
                txtRoomNum.Clear()
                chkAttending.Checked = True
                txtFirstName.Focus()
            End Sub
        
            Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
                Dim IDNum As Integer = txtID.Text
                Dim row As DataRow = LabelPrinterDS.tblEmployees.FindByID(IDNum)
                LabelPrinterDS.tblEmployees.Rows.Remove(row)
        
                txtID.Clear()
                txtID.Focus()
            End Sub
        
            Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
                My.Forms.frmPrinting.Show()
            End Sub
        
            Private Sub txtFirstName_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtFirstName.GotFocus, txtLastName.GotFocus, txtRoomNum.GotFocus, txtID.GotFocus
                sender.Backcolor = Color.LemonChiffon
            End Sub
        
            Private Sub txtFirstName_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtFirstName.KeyPress
                If e.KeyChar = Chr(Keys.Enter) Then
                    txtLastName.Focus()
                End If
            End Sub
        
            Private Sub txtLastName_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtLastName.KeyPress
                If e.KeyChar = Chr(Keys.Enter) Then
                    txtRoomNum.Focus()
                End If
            End Sub
        
            Private Sub txtRoomNum_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtRoomNum.KeyPress
                If e.KeyChar = Chr(Keys.Enter) Then
                    chkAttending.Focus()
                End If
            End Sub
        
            Private Sub txtID_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtID.KeyPress
                If e.KeyChar = Chr(Keys.Enter) Then
                    btnDelete.Focus()
                End If
            End Sub
        
            Private Sub txtFirstName_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtFirstName.LostFocus, txtLastName.LostFocus, txtRoomNum.LostFocus, txtID.LostFocus
                sender.BackColor = Color.White
            End Sub
        
            Private Sub chkAttending_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles chkAttending.KeyPress
                If e.KeyChar = Chr(Keys.Enter) Then
                    btnAdd.Focus()
                End If
            End Sub
        End Class
        Code for form 2 (I haven't written the code for the buttons yet, I am working on the math for spacing.
        Code:
        Public Class frmPrinting
        
            Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
                End
            End Sub
        
            Private Sub btnBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
                My.Forms.frmLabelPrinter.Show()
            End Sub
        
            Private Sub btnPrintPreview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrintPreview.Click
                ppdDialog.ShowDialog()
            End Sub
        
            Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
                pdDocument.Print()
            End Sub
        
        End Class
        No problem, thanks for your prompt reply. Please stay tuned. Someone should see this and will likely help or at least point you in the right direction...

        Comment

        Working...