A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Message Box displays on date criteria



 
 
Thread Tools Display Modes
  #1  
Old July 1st, 2009, 05:14 PM posted to microsoft.public.access.forms
a1_robs via AccessMonster.com
external usenet poster
 
Posts: 3
Default Message Box displays on date criteria

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!

--
Message posted via http://www.accessmonster.com

  #2  
Old July 1st, 2009, 07:18 PM posted to microsoft.public.access.forms
Linq Adams via AccessMonster.com
external usenet poster
 
Posts: 1,474
Default Message Box displays on date criteria

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

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

Message posted via http://www.accessmonster.com

  #3  
Old July 3rd, 2009, 09:47 AM posted to microsoft.public.access.forms
a1_robs via AccessMonster.com
external usenet poster
 
Posts: 3
Default Message Box displays on date criteria

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.

--
Message posted via http://www.accessmonster.com

  #4  
Old July 3rd, 2009, 09:50 AM posted to microsoft.public.access.forms
a1_robs via AccessMonster.com
external usenet poster
 
Posts: 3
Default Message Box displays on date criteria

Just worked out how to do it! Cancel = False.

Rob.

--
Message posted via http://www.accessmonster.com

  #5  
Old March 21st, 2010, 02:45 PM posted to microsoft.public.access.forms
Noemi Albistur
external usenet poster
 
Posts: 2
Default Message Box displays on date criteria

quiero mi autentico correo hotmail no este trucho que no pedi

"a1_robs via AccessMonster.com" u49836@uwe escribió en el mensaje de
noticias:986e12e564657@uwe...
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!

--
Message posted via http://www.accessmonster.com

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 06:52 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.