Message Box displays on date criteria

  • Thread starter a1_robs via AccessMonster.com
  • Start date
A

a1_robs via AccessMonster.com

Hi All,

I am trying to create some code to make a message box appear on a form, when
the 'DestroyDate' field value is less than the 'AddDate' field value plus 365
days.

The code I have tried in the Before Update event on the text box is:

Private Sub DestroyDate_BeforeUpdate(Cancel As Integer)

=IIf([DestroyDate] < ([AddDate] + 365),MsgBox("WARNING! Destroy Date is less
than one year!"),0)

End Sub

I get a message saying Compile Error: Syntax Error.

Can anyone spot where I have gone wrong?

Thanks in advance for your help!
 
L

Linq Adams via AccessMonster.com

To be honest, I have no idea what you were trying to do using IIF()!

But this should do the job:

Private Sub DestroyDate_BeforeUpdate(Cancel As Integer)
If Me.DestroyDate < Me.AddDate + 365 Then
MsgBox "WARNING! Destroy Date is less than one year!"
Cancel = True
End If
End Sub
 
A

a1_robs via AccessMonster.com

Hi Linq,

Thanks very much for the code - it works perfectly. The only slight problem
is that it will not now allow me to save the record with a 'DestroyDate' less
that one year after the AddDate, as the message keeps re-appearing. Can you
think of a way to get round this. Could I set the focus to the next text box
(DestroyMethod)?

Thanks again,

Rob.
 

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