NorthbyNorthwest
Board Regular
- Joined
- Oct 27, 2013
- Messages
- 173
- Office Version
- 365
Hi, everyone. I am having trouble with code for checking if a textbox is empty. The empty textbox triggers a message to enter info in textbox. It then returns me the first page in my multipage form and sets focus to the textbox. The trouble is once I actually enter info in the textbox I cannot get out of the textbox. Doesn't matter if I hit tab or enter or use mouse. The cursor remains in the textbox, and I keep getting message that textbox is empty. Below are to to pieces of code I've tried with the same results. Help!
Above code is from Add button sub routine.
I also tried code below with Exit and BeforeUpdate events. Same results as above. What am I doing wrong?
VBA Code:
If Me.txtID = vbNullString And Me.cboAuditGrp = "Unit 1" Or Me.cboAuditGrp = "Unit 3" And Me.cboReviewStatus = "Routine" Or Me.cboReviewStatus = "Makeup" Or Me.cboReviewStatus = "Double" Or Me.cboReviewStatus = "OJT (feedback only)" Or Me.cboReviewStatus = "Feedback" Then
MsgBox "Please enter the audit's ID number.", vbOKOnly + vbInformation, "Missing ID"
Me.MultiPage1.value = 0
Me.txtID.SetFocus
Exit Sub
End If
Above code is from Add button sub routine.
I also tried code below with Exit and BeforeUpdate events. Same results as above. What am I doing wrong?
Code:
Private Sub txtID_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Trim(txtID.value & vbNullString) = vbNullString And cboAuditGrp = "Unit 1" Or cboAuditGrp = "Unit 3" And cboReviewStatus = "Routine" Or cboReviewStatus = "Makeup" Or cboReviewStatus = "Double" Or cboReviewStatus = "OJT (feedback only)" Or cboReviewStatus = "Feedback" And Me.Visible Then
MsgBox "Please enter the audit's ID number."
Cancel = True
MultiPage1.value = 0
txtID.SetFocus
Else
'do nothing
End If
End Sub