Hi everyone,
I have code that requires data to be entered in two controls. I test this by using the following example code:
Private Sub ctlTruckCoName_LostFocus()
If IsNull(ctlTruckCoName) Then
strWarning = "Please either ENTER a Trucking Company Name" & Chr(10) & Chr(13) & Chr(13) _
& "or CLICK the 'Exit Add Trucker/Vehicle' Button."
MsgBox strWarning, vbCritical + vbOKOnly, "No Trucking Company Name."
Me.cmdCancelAdd.SetFocus
End If
End Sub
I have an exit button on the form that exits and returns to a control form without saving or doing any thing with any changes in this form. In the code above you will see that I change the focus from the ctlTruckCoName control to the cmdCancelAdd control. This avoids a circular situation in nothing entered in the control would continually move back to the field.
What I wish to happen is this code is executed any time focus is moved to a different control other than the cmdCancelAdd control. If the cmdCancelAdd control is clicked I wish to exit the form without the above code being exercised. I would also like the above code executed and focus returned to the ctlTruckCoName control anytime focus tries to move to a control other than the cmdCancelAdd control.
I don't know if there is a way to tell from an active control what control was clicked, but that seems to be what I need to do. If I knew the cmdCancelAdd button (control) had been pressed while the ctlTruckCoName control has the focus I could then skip executing this code.
Is there a way to do this?
Cuyler Smith