B Blyden
asked on
Exit sub without triggering AfterUpdate
Hello,
I have disabled the X on my userform and have an added a exit button on the form. I routine in the txtStudentID_AfterUpdate() field. If the user enters their studentID in that field and then deletes/backspace and tries to exit the form, the routine still runs. I just want it to allow the user to exit. They basically have to hit exit twice. I played around with this for a while and just can't figure out how to get around it. Don't want the user to msgbox when exiting.
Exit Button
I have disabled the X on my userform and have an added a exit button on the form. I routine in the txtStudentID_AfterUpdate()
Private Sub txtEmpNumber_AfterUpdate()
'Connects to dba
Dim rs As Object, strSQL As String
' connect to the Access database
Set cn = New ADODB.Connection
myConn = TARGET_DB
With cn
.Provider = "Microsoft.ACE.OLEDB.12.0"
.Open myConn
End With
'create recordset
Set rs = New ADODB.Recordset
src = "SELECT StudentName FROM qryStudentDB WHERE [StudentID]='" & Me.txtStudentID.Value & "'"
Set rs = New ADODB.Recordset
rs.Open src, cn, adOpenStatic
If rs.RecordCount = 0 Then
rs.Close
Set myConn = Nothing
Set rs = Nothing
MsgBox "No Records Found"
' Me.txtStudentID.SetFocus
Exit Sub
End If
txtStudentName.Text = rs(0)
Set rs = Nothing
End Sub
Exit Button
Private Sub cmdExit_Click()
Unload Me
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER