By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,101 Members | 1,359 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,101 IT Pros & Developers. It's quick & easy.

Printing from a Database in VB 2005 Express

P: 5
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.
Mar 26 '07 #1
Share this Question
Share on Google+
3 Replies


Dököll
Expert 100+
P: 2,364
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
Mar 26 '07 #2

P: 5
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
Expand|Select|Wrap|Line Numbers
  1. Public Class frmLabelPrinter
  2.  
  3.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  4.         'TODO: This line of code loads data into the 'LabelPrinterDS.tblEmployees' table. You can move, or remove it, as needed.
  5.         Me.TblEmployeesTableAdapter.Fill(Me.LabelPrinterDS.tblEmployees)
  6.  
  7.     End Sub
  8.  
  9.     Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
  10.         End
  11.     End Sub
  12.  
  13.     Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
  14.         Try
  15.             If chkAttending.Checked = True Then
  16.                 TblEmployeesTableAdapter.Insert(txtFirstName.Text, txtLastName.Text, txtRoomNum.Text, True)
  17.                 Me.TblEmployeesTableAdapter.Fill(Me.LabelPrinterDS.tblEmployees)
  18.             End If
  19.             If chkAttending.Checked = False Then
  20.                 TblEmployeesTableAdapter.Insert(txtFirstName.Text, txtLastName.Text, txtRoomNum.Text, False)
  21.                 Me.TblEmployeesTableAdapter.Fill(Me.LabelPrinterDS.tblEmployees)
  22.             End If
  23.         Catch ex As Exception
  24.             MessageBox.Show(ex.Message, "Data Input Error")
  25.         End Try
  26.  
  27.         txtFirstName.Clear()
  28.         txtLastName.Clear()
  29.         txtRoomNum.Clear()
  30.         chkAttending.Checked = True
  31.         txtFirstName.Focus()
  32.     End Sub
  33.  
  34.     Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
  35.         Dim IDNum As Integer = txtID.Text
  36.         Dim row As DataRow = LabelPrinterDS.tblEmployees.FindByID(IDNum)
  37.         LabelPrinterDS.tblEmployees.Rows.Remove(row)
  38.  
  39.         txtID.Clear()
  40.         txtID.Focus()
  41.     End Sub
  42.  
  43.     Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
  44.         My.Forms.frmPrinting.Show()
  45.     End Sub
  46.  
  47.     Private Sub txtFirstName_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtFirstName.GotFocus, txtLastName.GotFocus, txtRoomNum.GotFocus, txtID.GotFocus
  48.         sender.Backcolor = Color.LemonChiffon
  49.     End Sub
  50.  
  51.     Private Sub txtFirstName_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtFirstName.KeyPress
  52.         If e.KeyChar = Chr(Keys.Enter) Then
  53.             txtLastName.Focus()
  54.         End If
  55.     End Sub
  56.  
  57.     Private Sub txtLastName_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtLastName.KeyPress
  58.         If e.KeyChar = Chr(Keys.Enter) Then
  59.             txtRoomNum.Focus()
  60.         End If
  61.     End Sub
  62.  
  63.     Private Sub txtRoomNum_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtRoomNum.KeyPress
  64.         If e.KeyChar = Chr(Keys.Enter) Then
  65.             chkAttending.Focus()
  66.         End If
  67.     End Sub
  68.  
  69.     Private Sub txtID_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtID.KeyPress
  70.         If e.KeyChar = Chr(Keys.Enter) Then
  71.             btnDelete.Focus()
  72.         End If
  73.     End Sub
  74.  
  75.     Private Sub txtFirstName_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtFirstName.LostFocus, txtLastName.LostFocus, txtRoomNum.LostFocus, txtID.LostFocus
  76.         sender.BackColor = Color.White
  77.     End Sub
  78.  
  79.     Private Sub chkAttending_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles chkAttending.KeyPress
  80.         If e.KeyChar = Chr(Keys.Enter) Then
  81.             btnAdd.Focus()
  82.         End If
  83.     End Sub
  84. End Class
  85.  
Code for form 2 (I haven't written the code for the buttons yet, I am working on the math for spacing.
Expand|Select|Wrap|Line Numbers
  1. Public Class frmPrinting
  2.  
  3.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
  4.         End
  5.     End Sub
  6.  
  7.     Private Sub btnBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
  8.         My.Forms.frmLabelPrinter.Show()
  9.     End Sub
  10.  
  11.     Private Sub btnPrintPreview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrintPreview.Click
  12.         ppdDialog.ShowDialog()
  13.     End Sub
  14.  
  15.     Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
  16.         pdDocument.Print()
  17.     End Sub
  18.  
  19. End Class
  20.  
Mar 26 '07 #3

Dököll
Expert 100+
P: 2,364
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
Expand|Select|Wrap|Line Numbers
  1. Public Class frmLabelPrinter
  2.  
  3.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  4.         'TODO: This line of code loads data into the 'LabelPrinterDS.tblEmployees' table. You can move, or remove it, as needed.
  5.         Me.TblEmployeesTableAdapter.Fill(Me.LabelPrinterDS.tblEmployees)
  6.  
  7.     End Sub
  8.  
  9.     Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
  10.         End
  11.     End Sub
  12.  
  13.     Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
  14.         Try
  15.             If chkAttending.Checked = True Then
  16.                 TblEmployeesTableAdapter.Insert(txtFirstName.Text, txtLastName.Text, txtRoomNum.Text, True)
  17.                 Me.TblEmployeesTableAdapter.Fill(Me.LabelPrinterDS.tblEmployees)
  18.             End If
  19.             If chkAttending.Checked = False Then
  20.                 TblEmployeesTableAdapter.Insert(txtFirstName.Text, txtLastName.Text, txtRoomNum.Text, False)
  21.                 Me.TblEmployeesTableAdapter.Fill(Me.LabelPrinterDS.tblEmployees)
  22.             End If
  23.         Catch ex As Exception
  24.             MessageBox.Show(ex.Message, "Data Input Error")
  25.         End Try
  26.  
  27.         txtFirstName.Clear()
  28.         txtLastName.Clear()
  29.         txtRoomNum.Clear()
  30.         chkAttending.Checked = True
  31.         txtFirstName.Focus()
  32.     End Sub
  33.  
  34.     Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
  35.         Dim IDNum As Integer = txtID.Text
  36.         Dim row As DataRow = LabelPrinterDS.tblEmployees.FindByID(IDNum)
  37.         LabelPrinterDS.tblEmployees.Rows.Remove(row)
  38.  
  39.         txtID.Clear()
  40.         txtID.Focus()
  41.     End Sub
  42.  
  43.     Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
  44.         My.Forms.frmPrinting.Show()
  45.     End Sub
  46.  
  47.     Private Sub txtFirstName_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtFirstName.GotFocus, txtLastName.GotFocus, txtRoomNum.GotFocus, txtID.GotFocus
  48.         sender.Backcolor = Color.LemonChiffon
  49.     End Sub
  50.  
  51.     Private Sub txtFirstName_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtFirstName.KeyPress
  52.         If e.KeyChar = Chr(Keys.Enter) Then
  53.             txtLastName.Focus()
  54.         End If
  55.     End Sub
  56.  
  57.     Private Sub txtLastName_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtLastName.KeyPress
  58.         If e.KeyChar = Chr(Keys.Enter) Then
  59.             txtRoomNum.Focus()
  60.         End If
  61.     End Sub
  62.  
  63.     Private Sub txtRoomNum_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtRoomNum.KeyPress
  64.         If e.KeyChar = Chr(Keys.Enter) Then
  65.             chkAttending.Focus()
  66.         End If
  67.     End Sub
  68.  
  69.     Private Sub txtID_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtID.KeyPress
  70.         If e.KeyChar = Chr(Keys.Enter) Then
  71.             btnDelete.Focus()
  72.         End If
  73.     End Sub
  74.  
  75.     Private Sub txtFirstName_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtFirstName.LostFocus, txtLastName.LostFocus, txtRoomNum.LostFocus, txtID.LostFocus
  76.         sender.BackColor = Color.White
  77.     End Sub
  78.  
  79.     Private Sub chkAttending_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles chkAttending.KeyPress
  80.         If e.KeyChar = Chr(Keys.Enter) Then
  81.             btnAdd.Focus()
  82.         End If
  83.     End Sub
  84. End Class
  85.  
Code for form 2 (I haven't written the code for the buttons yet, I am working on the math for spacing.
Expand|Select|Wrap|Line Numbers
  1. Public Class frmPrinting
  2.  
  3.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
  4.         End
  5.     End Sub
  6.  
  7.     Private Sub btnBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
  8.         My.Forms.frmLabelPrinter.Show()
  9.     End Sub
  10.  
  11.     Private Sub btnPrintPreview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrintPreview.Click
  12.         ppdDialog.ShowDialog()
  13.     End Sub
  14.  
  15.     Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
  16.         pdDocument.Print()
  17.     End Sub
  18.  
  19. End Class
  20.  
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...
Mar 27 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.