Creating an Error Message.

vX987

Registered User.
Local time
Today, 15:12
Joined
Jun 29, 2007
Messages
51
Is it possible to create an action in Acces like this:

If control1 is null then error pop-up message appears
.... when you try to click anywhere else on the form

HOWEVER If control1 is NOT null (has data in it) then the error pop-up message would NOT appear when you click anywhere on the form.

My main focus is the Error Pop-up mess. I tried creating a Macro for on click, BUT it appears everytime I click (which is OBVIOUS).

Is this possible? If so, I'd appreciate some assistance in writing out such a code.

THANK THANK YOU.
 
Last edited:
If I understand you correctly, in Control1's "On Exit" or "Lost Focus" Event place the code:
IF ISNULL(me.Control1.value) Then
MsgBox "Error, This control can not be null",vbExclamation, "Error"
me.Control1.SetFocus
End If
 
If you place your code in the On Exit (and/or Lost Focus) event for the field you can test the value held in the field and then produce a pop-pop, such as:

Code:
If Is Null(me.MyFieldName.Value) or me.txtMyFieldName.Value="" THEN
        MsgBox"<your message".
        Me.MyFieldName.setfocus
    End If

This will put the cursor back in the field until the user enters some data (but it won't check how valid that data is).

HTH

Tim
 
Thank You sierra467 and Tim L!!

The only problem to this is that the message box only appears when I click on a different control. I want it to appear whenever I click ANYWHERE whether its a control or the form. Maybe this is not even possible.... Hrms..

this is the code RuralGuy gave me awhile back, but it created a lot of problems. The msgbox appeared anytime I clicked anywhere, HOWEVER, whenever I create a new record the msgbox would appear constantly until I clicked OK quite a few times before it would go away.

Code:
Private Sub Form_Current()

Me.VisitDateMain.SetFocus

End Sub

Private Sub VisitDateMain_Exit(Cancel As Integer)

If Not IsDate(Me.VisitDateMain) Then
   MsgBox "Please enter a valid date"
   Cancel = True
End If

End Sub

BUT THE CODE YOU BOTH GAVE ME WILL DO FOR NOW.

Thank you again.
 
Last edited:
If you use the Mouse Move event (as well as the Lost Focus event, incase someone is using the keyboard to navigate between fields (shock, it does happen though!)) of the form, this will trigger the checking code whenever the mouse is moved away from the field, as well as any time the mouse actually moves towards or, in fact, anywhere over the form... (so not so good afterall then).

Better would be use the On Click even of the form, as well as the Lost Focus even of the control, because people who click into controls very often move the mouse away whilst they type (and then move it back again, then away... an awful lot of time is spent moving the mouse when they could just be typing away.... oh sorry, was I rambling, lol).

Both of these methods will, unfortunately, trigger the check mechanism anytime you click on the form (or move the mouse over it), although if the field has data in it then you should not get any messages.

The problem is you want something that works all the time, but you don't want something that works all the time... I don't understand why you need to carry the check out if someone only clicks on the form (as opposed to another control) as the only time that it really matters is when they try to enter data into another field, or to go to another record, and they should both be captured by the Lost Focus event.

HTH

Tim

ps: apologies for not keeping the name of the control consistent in my earlier reply, I just realised that I had left one different from the others, still I guess you got the gist of it.
 

Users who are viewing this thread

Back
Top Bottom