Results 1 to 3 of 3
  1. #1
    4 Star Lounger
    Join Date
    Jun 2001
    Location
    Edinburgh, Midlothian, Scotland
    Posts
    492
    Thanks
    0
    Thanked 0 Times in 0 Posts

    System Test Date (Access XP)

    Next silly question from me.

    In order to test many of the functions/events on a database, it is often necessary to test using a false date, as different actions occur depending on whether a date is eg the 1st of a month or not.

    I've always done this by changing the Windows date, but this can give minor problems particularly if using system dates in the future or scheduled Tasks for back-ups etc. It
    is also quite easy to forget to re-set the date afterwards. Is there any way to declare a system date for use in Access, while leaving the
    Windows date un-altered?

    Colin

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: System Test Date (Access XP)

    No, but what would that solve? It would be just as easy, or perhaps even easier, to forget to reset the Access date, causing all your databases to use the wrong date.

    You could do something like the following, but I don't know if it's worth the hassle:
    - Create a table tblTestDate with a single Date/Time field TestDate.
    - Create a custom function in a standard module:

    Public Function MyDate() As Date
    MyDate = Nz(DLookup("TestDate", "tblTestDate"), Date)
    End If

    - Replace all occurrences of Date() in queries, expressions etc. by MyDate(), and of Date as a function in VBA code by MyDate.

    If you enter a date in tblTestDate, MyDate will return that date, so you can easily test for different dates by changing the date in the table. If you clear the field in the table, MyDate will return the current date. So, for production, make sure that the field in the table is cleared.

    Note 1: using MyDate instead of Date may have a negative impact on performance; it will only be noticeable in queries that process a large number of records, etc.
    Note 2: if you use MyDate in queries, you'll run into trouble if you want to use this query from another application using ODBC. ODBC doesn't know about custom functions.

  3. #3
    4 Star Lounger
    Join Date
    Jun 2001
    Location
    Edinburgh, Midlothian, Scotland
    Posts
    492
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: System Test Date (Access XP)

    Yes you're right that it would be as easy to forget to change it back.

    But If I set a piece of code as a reminder to chenge the code back then I'll be getting a system reminder to do so I can also put an extra level on the switchboard which will take me into a test environment or a production one. If I choose the latter, it will check the system date versus MyDate and report any variation. AGain this will avoid going into production mode with a false date.

    I believe it will be worth the hassle in this case, although I'll probably leave it a few days before looking at it.

    Thanks again.


    Colin

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •