in my userform i have three textboxes(1,2,3) and a button
i want the user must enter something in it
if u leave blank it should display an msg that u must enter an message in it
Private Sub cmdbt1_Click()
Dim irow As Long
Dim ws As Worksheet
Dim info
info = IsWorkBookopen("\\bms\Service log request\login details\workstation.xlsx")
'we open the workbook if it is closed
If info = False Then
Workbooks.Open ("\\bms\Service log request\login details\workstation.xlsx")
End If
Set ws = Worksheets("Login Time")
'Find first empty row in database
irow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
'Check for a Name number
If Trim(Me.TextBox1.Value) = "" Then
Me.TextBox2.SetFocus
End If
'Copy the data to the database
ws.Cells(irow, 1).Value = Me.lbl2.Object
ws.Cells(irow, 3).Value = Me.lbl4.Object
ws.Cells(irow, 4).Value = Me.lbl6.Object
ws.Cells(irow, 2).Value = Me.Label2.Object
ws.Cells(irow, 5).Value = Me.TextBox3.Value
ws.Cells(irow, 6).Value = Me.TextBox1.Value
ws.Cells(irow, 7).Value = Me.TextBox2.Value
'Me.lbl2.Name = ""
'Me.lbl4.Name = ""
Me.TextBox1.Value = ""
Me.TextBox2.Value = ""
Me.TextBox3.Value = ""
Me.TextBox1.SetFocus
'Application.DisplayAlerts = False
Workbooks("workstation.xlsx").Save
Workbooks("workstation.xlsx").Close
Application.DisplayAlerts = True
MsgBox "welcome to bms"
MsgBox "Don't Forget to Logout before Shutdown system"
End Sub
Bookmarks