Message box for form regarding DOB

  • Thread starter SamMexico via AccessMonster.com
  • Start date
S

SamMexico via AccessMonster.com

Hi everyone,

I have gotten a bit stuck trying to set up a message box that opens if the
form record shows the date of birth as over 2 years old. Ideally when any
record is opened and the DOB has been entered the message box should appear
warning the user (but not if the text box is empty). There should also be a
button to deactivate the warning box for each individual record.

The form itself has a 'DOB' text box field but no age specifications.

If anyone could help me out I would be really grateful

Sam
 
S

SamMexico via AccessMonster.com

Sorry - just to clarify; when a person reaches 2 years old I would like the
message box to warn the user....

Cheers,

Sam
 
S

SamMexico via AccessMonster.com

but also to have a cut off point when the person is over 16 years of age -
the limitations just keep getting bigger...:)
 
D

Daryl S

Sam -

For a button to deactivate the warning, that would need to be bound to a
field in the table so that this could be 'remembered'. A checkbox would be
better than a button for this. Assuming you have added the 'ignoreWarning'
field and the appropriate checkbox on the form, then you can add code to
display a message only if the DOB is more than two but less than 16 years ago:

If not me.IgnoreWarning Then
If (DateAdd("yyyy",2,nz(Me.DOB,0)) > Date()) AND
(DateAdd("yyyy",16,nz(Me.DOB,Date())) < Date()) Then
msgbox("DOB is over 2 years ago")
End If
End If

This code would be in the AfterUpdate event of the DOB field if you want the
message to come up when the DOB is changed (as long as the IngoreWarning was
false).
This code would be in the OnCurrent event of the form if you want the
message to come up when a user moves to this record.

That should get you started...
 
J

John W. Vinson

Hi everyone,

I have gotten a bit stuck trying to set up a message box that opens if the
form record shows the date of birth as over 2 years old. Ideally when any
record is opened and the DOB has been entered the message box should appear
warning the user (but not if the text box is empty). There should also be a
button to deactivate the warning box for each individual record.

The form itself has a 'DOB' text box field but no age specifications.

If anyone could help me out I would be really grateful

Sam

I'd suggest adding a Yes/No field HasBeenWarned to the table (otherwise you
won't be able to remember that a warning has been cancelled for this record).

You can then put code in the form's Current event to display the warning. This
can be done several ways, some more intrusive than others. Simplest would be
to just have a big Label control with a caption expressing the warning; have
the label be invisible, and put code in the current event such as

Private Sub Form_Current()
Me!lblWarning.Visible = False ' hide warning by default
If (Not Me!HasBeenWarned) And Not IsNull(Me!DOB) Then
If DateAdd("yyyy", 2, [DOB]) > Date() _
OR DateAdd("yyyy", 16, [DOB]) < Date() Then
Me!lblWarning.Visible = True
End If
End Sub

You can also use MsgBox to pop up a warning message, or take some other
appropriate action.
 
S

SamMexico via AccessMonster.com

Hi John, thanks for your help - I followed your instructions : added a Yes/No
field to the table, put the code into the Current event and added the big
label control. I tested it using a new record with a data just over 2 years
ago but nothing seemed to happen - any ideas?

Thanks,

Sam
 
D

Daryl S

Sam -

You will want to enter the same code on the BeforeUpdate event of the form,
or the AfterUpdate event of the DOB field so the error displays. I would
also include an Else clause to set the .visible to false for the cases where
the criteria is not met.

I don't see any code to turn the warning off if they have been warned
already, so you may want to include setting the Yes/No field to Yes whenever
you display the warning label.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top