473,320 Members | 2,041 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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.
Mar 26 '07 #1
3 1197
Dököll
2,364 Expert 2GB
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
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
2,364 Expert 2GB
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

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

Similar topics

1
by: Michael | last post by:
Hi, I've read Scott's article: http://weblogs.asp.net/scottgu/archive/2005/08/25/423703.aspx but when I try to create a new database file in App_Data with Visual Studio 2005, it shows error: ...
2
by: Patrick F | last post by:
Hi, i have SQL Server 2005 and a database set that is called, myCompany the problem is that i cant connect from my page to it, here is from the web.config: ( i have got this connectionstring from...
5
by: Glen Buell | last post by:
Hi all, I have a major problem with my ASP.NET website and it's SQL Server 2005 Express database, and I'm wondering if anyone could help me out with it. This site is on a webhost...
14
by: Johnny Jörgensen | last post by:
Hi all I just saw an ad in the latest ComponentSource newsletter for a database engine called VistaDB 3.0. http://www.vistadb.net/default.asp It looks very interesting as a database engine...
10
by: AAaron123 | last post by:
I want to create a database with one table on the host. I can't user SQL Server Management Studio to do it so I guess I have to do it programmatically. I have in mind that in the session start...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.