Make field required on AfterUpdate

ppataki

Registered User.
Local time
Today, 05:27
Joined
Sep 5, 2008
Messages
267
Dear All,

I have a form where user can select Status, after Status is selected, and if the Progress field is empty I put a msgbox on screen, stating that all the required fields need to be filled in and looped it until field is filled in
(Progress field is not set as required because during regular data uploads this field is empty, so if I set it as required I cant do the data upload)

My problem is that it keeps giving me the msgbox and I have no chance to enter data in the Progress field
Here is the code so far:

Code:
Private Sub Status_AfterUpdate()
Dim stMessage As String
If Me.Status <> "Open" And IsNull(Me.Progress) = True Then
Do While IsNull(Me.Progress) = True
stMessage = "Please fill in all the required fields!"
MsgBox stMessage, vbCritical, "Attention!"
Loop
Else
End If

End Sub
Code:

Could you please advise on how I can have the possibility to enter data and then recheck the if ?

Many thanks in advance! ;)
 
Do While IsNull(Me.Progress) = True
stMessage = "Please fill in all the required fields!"
MsgBox stMessage, vbCritical, "Attention!"
Loop

You are looping this... obviously this is never going to exit...
Instead is if /endif to check instead of Do while/loop and set the focus (me.Progress.setfocus) to the progress bar.
Then enable a check on it "on exit" or "on lost focus" or something to force data to be entered before leaving this box.

I hope this helps, good luck!
 
you need validation stuff, like this this in the FORM's BEFOREUPDATE event.

ie BEFORE you allow the record to be saved, you check whatever fields you require.

if the validation checks fail, then set cancel to be true, and the record will not be written
 
Thank you for the hint, I modified the code to get focus on Progress

Private Sub Status_AfterUpdate()
Dim stMessage As String
If Me.Status <> "Open" And IsNull(Me.Progress) = True Then
stMessage = "Please fill in all the required fields!"
MsgBox stMessage, vbCritical, "Attention!"
Me.Progress.SetFocus
Else
End If

The problem is that now I dont really know how to "enable a check on it"
On lost focus of Progress field I should write:
if isnull(Progress) = True
then
something that would force data entry

Could you please advise?

Thank you in advance
 
Simply msg them and set the focus back!
Somethign like
if isnull() then
msgbox "Boooooooooooooooooooooooeeeeeeeeeeeeeeeeeehhhhhhhhhhhhh"
setfocus
endif
 
Maybe I do something incorrectly but if I use this code:

Private Sub Progress_LostFocus()
Dim stmessage As String
If IsNull(Progress) = True Then
stmessage = "Please fill in all the required fields!"
MsgBox stmessage, vbCritical, "Attention!"
Me.Progress.SetFocus
End If

End Sub

Focus is on Progress (it is empty), I push Tab button (or click on any other fields), msgbox appears then the focus is not restored to Progress, it just goes to the next field! (so user is not forced to fill in the Progress field)

Could you please advise?
Thank you very much
 
Dear All,

FYI
the beforeupdate method on form level works perfectly!!

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.Progress) = True And Me.Status <> "open" Then
MsgBox "Please fill in all the required fields!", vbCritical, "Attention!"
Cancel = True
Me.Progress.SetFocus
End If
If IsNull(Me.Progress) = False And Me.Status = "open" Then
MsgBox "Open status cannot have Progress filled in!", vbCritical, "Attention!"
Cancel = True
Me.Progress.SetFocus
End If
End Sub

Thank you for your help!
 

Users who are viewing this thread

Back
Top Bottom