473,473 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Date Comparison in Access 2002 using VBA

Hi There,
I currently have a database in Access 2002 with several
forms. I would like to restrict access to one form in perticular until
November 1st every year. My current method (attempted method) is a
heavy handed, no nonsense, direct date comparison using VBA.

Function NovemberOnwards()
'Use with 'On Avtivate' on Orders form

CurrentDate = Date 'I cannot decide which function is best to use
'to get the current date

If CurrentDate < #11/1/2005# Then
Forms![Orders].Visible = False
End If
End Function

Any suggestions are welcome and thanks is given in advance,

Karl Gibbon
Nov 13 '05 #1
3 6539
This should work and will automatically fill in the year for you.

If Date < DateSerial(Year(Date), 11, 1) Then

Also, your method will hide the form, but still allow it to be opened. If
you want to prevent it from even being opened, you could make the same check
in the form's Open event and set Cancel=True if the date doesn't fit.

Example:
Cancel = (Date < DateSerial(Year(Date), 11, 1))

--
Wayne Morgan
MS Access MVP
"Karl Gibbon" <gi*******@hotmail.com> wrote in message
news:13**************************@posting.google.c om...
Hi There,
I currently have a database in Access 2002 with several
forms. I would like to restrict access to one form in perticular until
November 1st every year. My current method (attempted method) is a
heavy handed, no nonsense, direct date comparison using VBA.

Function NovemberOnwards()
'Use with 'On Avtivate' on Orders form

CurrentDate = Date 'I cannot decide which function is best to use
'to get the current date

If CurrentDate < #11/1/2005# Then
Forms![Orders].Visible = False
End If
End Function

Any suggestions are welcome and thanks is given in advance,

Karl Gibbon

Nov 13 '05 #2
"Wayne Morgan" <co***************************@hotmail.com> wrote in message news:<ba*******************@newssvr11.news.prodigy .com>...
This should work and will automatically fill in the year for you.

If Date < DateSerial(Year(Date), 11, 1) Then

Also, your method will hide the form, but still allow it to be opened. If
you want to prevent it from even being opened, you could make the same check
in the form's Open event and set Cancel=True if the date doesn't fit.

Example:
Cancel = (Date < DateSerial(Year(Date), 11, 1))


Indeed your method does work, however there seems to be slight flaw in
it somewhere. Upon opening the database i am greeted by the
switchboard which contains several buttons to open different forms,
one of which is the 'Orders' form which is the one i am concerend with
preventing access to before 1st November every year. I click on the
button to open this 'Orders' form and for some reason it is allowed to
open. I then open the module to view the code, and run it directly
from there using the 'Run' button and the recently opened 'Orders'
form is closed. The code will then work every time after that (I'm not
sure on this but i think it might be because the Date function can't
get the date for some reason unless the code is directly run ). I
don't see the point however, in having a piece of code to prevent
access to a particular form if it will only work if the code has
already been directly run.
Thanks for your suggestion Wayne and hope you can help me with this
new little problem.

Thanks also to anyone else who is kind enough to reply,

Karl Gibbon
Nov 13 '05 #3
I can't reproduce it here. The code works, even if I try to open the form
from the switchboard immediately after opening the database. Do you have any
other code in the Open event of the form that may be causing the problem?

--
Wayne Morgan
MS Access MVP
"Karl Gibbon" <gi*******@hotmail.com> wrote in message
news:13**************************@posting.google.c om...

Indeed your method does work, however there seems to be slight flaw in
it somewhere. Upon opening the database i am greeted by the
switchboard which contains several buttons to open different forms,
one of which is the 'Orders' form which is the one i am concerend with
preventing access to before 1st November every year. I click on the
button to open this 'Orders' form and for some reason it is allowed to
open. I then open the module to view the code, and run it directly
from there using the 'Run' button and the recently opened 'Orders'
form is closed. The code will then work every time after that (I'm not
sure on this but i think it might be because the Date function can't
get the date for some reason unless the code is directly run ). I
don't see the point however, in having a piece of code to prevent
access to a particular form if it will only work if the code has
already been directly run.

Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Daniel Fisher | last post by:
Hi All! I'm fairly new to PhP and basicly trying to learn right now. Now I have a problem - I have a fairly large collection of movies which people keep borrowing from me. And then not returning....
5
by: democratix | last post by:
Hi, I've only got a couple years experience developing for Access but have recently been experimenting with HTML/javascript for gui and client-side scripting, mysql for database and php for...
7
by: vnl | last post by:
I'm trying to run a SQL query but can't find any records when trying to select a certain date. Here's the sql: SELECT field 1, field2, date_and_time, FROM table1 WHERE date_and_time =...
30
by: Dr John Stockton | last post by:
It has appeared that ancient sources give a method for Numeric Date Validation that involves numerous tests to determine month length; versions are often posted by incomers here. That sort of code...
1
by: sylvian stone | last post by:
Hi, I've used standard date functions in the past, but need to create something a little different, as I am working on an investment calculator. What I need to do is validate two dates, and...
8
by: Ishbel Kargar | last post by:
Since upgrading from old laptop (Windows 98) to new laptop (Windows XP), my mail-merge letters are doing strange things with date formats. For instance, my reminder letter for lapsed subs carries...
7
by: Andy Davis | last post by:
I have a table of data in Access 2002 which is used as the source table for a mail merge document using Word 2002 on my clients PC. The data is transferred OK but I've noticed that any dates which...
18
by: dfetrow410 | last post by:
Anyone have some code that will do this? Dave
7
by: mr.nimz | last post by:
hello, this is antenio. recently i've come to a problem. i got a way through it, somehow, still it left me in a curious state, so i'm posting it here, if i can get an answer from some techy, ...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.