Jaye Cavallo
New Member
- Joined
- Mar 10, 2022
- Messages
- 45
- Office Version
- 2016
- Platform
- Windows
Hello,
I have created an Excel userform for an attendee to check in at an event. The userform collects first name, last name, email, mobile, etc. Then the user clicks the save button and the data is transferred to the Excel worksheet and creates a unique ID for each row of data. Keep in mind, the data is entered one at a time as the attendees check in. Therefore, every time an attendee checks in by entering their data, a new row and unique ID are created on the worksheet.
I am wondering if there is a way to print a name tag from the userform, so the attendee would click the button to save their information an print a name tag with at least first name, last name and unique id number on the name tag. The printer is a Zebra name tag printer.
Private Sub cmdSavePrint_Click()
'Validation
If Me.TextBox1.value = "" Then
MsgBox "Please enter your first name" ', vbCritical
Me.TextBox1.SetFocus
Exit Sub
End If
If Me.TextBox2.value = "" Then
MsgBox "Please enter your last name" ', vbCritical
Me.TextBox2.SetFocus
Exit Sub
End If
'Validation.
If Me.TextBox3.value = "" Then
MsgBox "Please enter a valid e-mail address" ', vbCritical
Me.TextBox3.SetFocus
Exit Sub
End If
Dim emptyRow As Long
'Make Sheet1 active
Worksheets("Registration").Activate
'Determine emptyRow
emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1
'Transfer information
If IsValidEmail(TextBox3) Then
'Transfer information
Cells(emptyRow, 1).value = TextBox1.value
Cells(emptyRow, 2).value = TextBox2.value
Cells(emptyRow, 3).value = TextBox3.value
Cells(emptyRow, 4).value = TextBox4.value
Cells(emptyRow, 5).value = TextBox5.value
Cells(emptyRow, 6).value = TextBox6.value
Cells(emptyRow, 7).value = TextBox7.value
Cells(emptyRow, 8).value = TextBox8.value
Cells(emptyRow, 9).value = TextBox9.value
Cells(emptyRow, 10).value = TextBox10.value
If obUpdatesYes.value = True Then
Cells(emptyRow, 11).value = "Yes"
ElseIf obUpdatesNo.value = True Then
Cells(emptyRow, 11).value = "No"
End If
vbclearResponse = MsgBox("Are you sure you print a name tag?", vbYesNoCancel + vbQuestion, "Print Name Tag and Clear Cell Contents")
If vbclearResponse = vbYes Then
Me.TextBox1.value = ""
Me.TextBox2.value = ""
Me.TextBox3.value = ""
Me.TextBox4.value = ""
Me.TextBox5.value = ""
Me.TextBox6.value = ""
Me.TextBox7.value = ""
Me.TextBox8.value = ""
Me.TextBox9.value = ""
Me.TextBox10.value = ""
ElseIf vbclearResponse = vbNo Then
'Code here if user clicked no
End If
Else
MsgBox "Please enter a valid email address." ', vbCritical
Me.TextBox3.SetFocus
End If
With Cells(emptyRow, "L")
.value = Left(.Offset(-1), 1) & Format(Mid(.Offset(-1), 2) + 1, "000000")
End With
End Sub
Private Sub frmInformation_Click()
End Sub
Private Sub UserForm_Initialize()
Worksheets("Registration").Activate
Dim ws As Worksheet
Set ws = Worksheets("Registration")
Me.TextBox1.SetFocus
End Sub
Private Sub CommandButton1_Click()
Worksheets("Registration").Activate
Dim firstname As String
Dim lastname As String
firstname = TextBox1.value
lastname = TextBox2.value
End Sub
Private Sub TextBox9_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Me.TextBox9.Text = Format(TextBox9.Text, "000-000-0000")
End Sub
Private Sub TextBox10_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Me.TextBox10.Text = Format(TextBox10.Text, "000-000-0000")
End Sub
Private Function IsValidEmail(value As String) As Boolean
Dim RE As Object
Set RE = CreateObject("vbscript.RegExp")
RE.Pattern = "^[a-zA-Z0-9\._-]+@([a-zA-Z0-9_-]+\.)+([a-zA-Z]{2,3})$"
IsValidEmail = RE.Test(value)
Set RE = Nothing
End Function
I have created an Excel userform for an attendee to check in at an event. The userform collects first name, last name, email, mobile, etc. Then the user clicks the save button and the data is transferred to the Excel worksheet and creates a unique ID for each row of data. Keep in mind, the data is entered one at a time as the attendees check in. Therefore, every time an attendee checks in by entering their data, a new row and unique ID are created on the worksheet.
I am wondering if there is a way to print a name tag from the userform, so the attendee would click the button to save their information an print a name tag with at least first name, last name and unique id number on the name tag. The printer is a Zebra name tag printer.
Private Sub cmdSavePrint_Click()
'Validation
If Me.TextBox1.value = "" Then
MsgBox "Please enter your first name" ', vbCritical
Me.TextBox1.SetFocus
Exit Sub
End If
If Me.TextBox2.value = "" Then
MsgBox "Please enter your last name" ', vbCritical
Me.TextBox2.SetFocus
Exit Sub
End If
'Validation.
If Me.TextBox3.value = "" Then
MsgBox "Please enter a valid e-mail address" ', vbCritical
Me.TextBox3.SetFocus
Exit Sub
End If
Dim emptyRow As Long
'Make Sheet1 active
Worksheets("Registration").Activate
'Determine emptyRow
emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1
'Transfer information
If IsValidEmail(TextBox3) Then
'Transfer information
Cells(emptyRow, 1).value = TextBox1.value
Cells(emptyRow, 2).value = TextBox2.value
Cells(emptyRow, 3).value = TextBox3.value
Cells(emptyRow, 4).value = TextBox4.value
Cells(emptyRow, 5).value = TextBox5.value
Cells(emptyRow, 6).value = TextBox6.value
Cells(emptyRow, 7).value = TextBox7.value
Cells(emptyRow, 8).value = TextBox8.value
Cells(emptyRow, 9).value = TextBox9.value
Cells(emptyRow, 10).value = TextBox10.value
If obUpdatesYes.value = True Then
Cells(emptyRow, 11).value = "Yes"
ElseIf obUpdatesNo.value = True Then
Cells(emptyRow, 11).value = "No"
End If
vbclearResponse = MsgBox("Are you sure you print a name tag?", vbYesNoCancel + vbQuestion, "Print Name Tag and Clear Cell Contents")
If vbclearResponse = vbYes Then
Me.TextBox1.value = ""
Me.TextBox2.value = ""
Me.TextBox3.value = ""
Me.TextBox4.value = ""
Me.TextBox5.value = ""
Me.TextBox6.value = ""
Me.TextBox7.value = ""
Me.TextBox8.value = ""
Me.TextBox9.value = ""
Me.TextBox10.value = ""
ElseIf vbclearResponse = vbNo Then
'Code here if user clicked no
End If
Else
MsgBox "Please enter a valid email address." ', vbCritical
Me.TextBox3.SetFocus
End If
With Cells(emptyRow, "L")
.value = Left(.Offset(-1), 1) & Format(Mid(.Offset(-1), 2) + 1, "000000")
End With
End Sub
Private Sub frmInformation_Click()
End Sub
Private Sub UserForm_Initialize()
Worksheets("Registration").Activate
Dim ws As Worksheet
Set ws = Worksheets("Registration")
Me.TextBox1.SetFocus
End Sub
Private Sub CommandButton1_Click()
Worksheets("Registration").Activate
Dim firstname As String
Dim lastname As String
firstname = TextBox1.value
lastname = TextBox2.value
End Sub
Private Sub TextBox9_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Me.TextBox9.Text = Format(TextBox9.Text, "000-000-0000")
End Sub
Private Sub TextBox10_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Me.TextBox10.Text = Format(TextBox10.Text, "000-000-0000")
End Sub
Private Function IsValidEmail(value As String) As Boolean
Dim RE As Object
Set RE = CreateObject("vbscript.RegExp")
RE.Pattern = "^[a-zA-Z0-9\._-]+@([a-zA-Z0-9_-]+\.)+([a-zA-Z]{2,3})$"
IsValidEmail = RE.Test(value)
Set RE = Nothing
End Function