![]() |
Return to UserForm
What can I do to take the user back to the UserForm (preferably to TextBox1)
if TextBox1 value is blank? Private Sub CommandButton1_Click() Dim rng Set rng = Cells(ActiveCell.Row, 1) Application.ScreenUpdating = False If TextBox1.Value = "" Then MsgBox "Sorry but you must provide a First Name" End End If Application.ScreenUpdating = False Range("A1003").Activate rng(1, 1).Value = TextBox1.Text 'Employee First Name Unload Add_Name Sort.SortEmplyees Application.ScreenUpdating = True End Sub |
Return to UserForm
I would think that:
Add_Name.TextBox1.SetFocus would work. "Patrick C. Simonds" wrote: What can I do to take the user back to the UserForm (preferably to TextBox1) if TextBox1 value is blank? Private Sub CommandButton1_Click() Dim rng Set rng = Cells(ActiveCell.Row, 1) Application.ScreenUpdating = False If TextBox1.Value = "" Then MsgBox "Sorry but you must provide a First Name" End End If Application.ScreenUpdating = False Range("A1003").Activate rng(1, 1).Value = TextBox1.Text 'Employee First Name Unload Add_Name Sort.SortEmplyees Application.ScreenUpdating = True End Sub |
Return to UserForm
First, it's not a good idea to use End to quit your routine. Lots of things can
go wrong (static variables will get reset to empties, null strings, 0's, nothings... If TextBox1.Value = "" Then MsgBox "Sorry but you must provide a First Name" Exit sub End If Second, why are you doing this at all? Range("A1003").Activate ======= Option Explicit Private Sub CommandButton1_Click() Dim rng as Range Set rng = activesheet.Cells(ActiveCell.Row, 1) If TextBox1.Value = "" Then MsgBox "Sorry but you must provide a First Name" Exit sub End If Application.ScreenUpdating = False rng(1, 1).Value = TextBox1.Text 'Employee First Name Unload Add_Name Sort.SortEmplyees Application.ScreenUpdating = True End Sub Is Add_Name the name of the userform that contains this Commandbutton? Option Explicit Private Sub CommandButton1_Click() Dim rng as Range Set rng = activesheet.Cells(ActiveCell.Row, 1) If TextBox1.Value = "" Then MsgBox "Sorry but you must provide a First Name" Exit sub End If Application.ScreenUpdating = False rng(1, 1).Value = TextBox1.Text 'Employee First Name me.hide Sort.SortEmplyees Application.ScreenUpdating = True unload me End Sub "Patrick C. Simonds" wrote: What can I do to take the user back to the UserForm (preferably to TextBox1) if TextBox1 value is blank? Private Sub CommandButton1_Click() Dim rng Set rng = Cells(ActiveCell.Row, 1) Application.ScreenUpdating = False If TextBox1.Value = "" Then MsgBox "Sorry but you must provide a First Name" End End If Application.ScreenUpdating = False Range("A1003").Activate rng(1, 1).Value = TextBox1.Text 'Employee First Name Unload Add_Name Sort.SortEmplyees Application.ScreenUpdating = True End Sub -- Dave Peterson |
All times are GMT +1. The time now is 02:37 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com