Seting a field on a form conditionally required

aymanmb

Registered User.
Local time
Today, 18:31
Joined
Jan 28, 2007
Messages
96
Hi,

I have a form based on a table with a text control storing "Enddate" and a checkbox names "Completed".

I want to write a code that will prompt/force the user to enter a date in the "EndDate" field if the "Completed" checkbox is checked.

otherwise, it is OK to leave the "EndDate" empty as far as the checkbox is unchecked.

thanks for the tip
 
If Me.Completed = True AND Not IsDate(Me.EndDate) Then
 
You may want to consider putting your code in the BeforeUpdate event of the CheckBox and not letting the user check it until the date was completed.

Code:
Private Sub chkBoxName_BeforeUpdate(Cancel As Integer)

If Not IsDate(Me.EndDate) Then
   MsgBox "Please complete the Ending Date first!"
   Cancel = True
End If

End Sub
...using your chkBoxName of course!
 
thaks a lot, it worked but one problem:

I can not go back to the date to enter the value because the error messgae reappear always i.e. I can not change the focus to the EndDate field
 
Please post the code you are using starting with Private Sub... thru End Sub so we can see it.
 
Private Sub Completed_BeforeUpdate(Cancel As Integer)

If Not IsDate(Me.EndDate) Then
MsgBox "Please complete the Ending Date first!"
Cancel = True
End If


End Sub
 
I had tested this process before making the suggestion and I just went back to make sure it works as expected. Are you saying that if you attempt to check the Completed CheckBox without first putting a date in the EndDate control, you get the warning and then you can not move the focus back to the EndDate control so you can complete it? Mine works just fine. Do you have any other code in either control?
 
One other idea. Leave the Completed check box DISABLED until a date is entered in the EndDate filed, then re-enable the completed check box after the appropriate date checking of course
 
Hi FoFa,
I like that even better than my idea! More intuitive.
 
Last edited:
It could be argued from a normalization standpoint that the checkbox is unnecessary. The presence of a date in the DateCompleted field indicates that the job is completed.
 
great responses, thanks a lot.

I agree that it could be eliminated in presence of an EndDate/Completeddate.

however for my learning curve, would apppreciate giving me an example code to make the checkbox disabled till a date is entered.

thanks a lot guys
 
How about taking your best shot at it and let us know how you make out?
 

Users who are viewing this thread

Back
Top Bottom