Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Emmanuel is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2020
    Posts
    272

    Correct system date before database can start successfully

    I have a database which works strictly with the system date(Computer date) to generate accurate results.


    I tested and realized that loading the database and entering transactions when your system date is wrong do cause some issues a times.

    I will like to know if there is any way to let my database check that the system date is correct( i.e. the date set is for that current day) before the database can load?
    Furthermore, if the system checks and the date is wrong, the database would give a prompt that will exit the database.

    Any help with this will be greatly appreciated

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,258
    All I could think of is code to check with an NTP server?

    Google for VBA code to sync system time.?

    Edit:
    I have found this code that will at least check if the date and time are correct?

    https://stackoverflow.com/questions/...-workbook-open

    Further edit:
    I never realised how simple it was to change system date and time?
    https://www.mrexcel.com/board/thread...ia-vba.252042/

    So now you should be good to go?

    HTH
    Last edited by Welshgasman; 06-21-2021 at 05:37 AM. Reason: Added link
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    Emmanuel is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2020
    Posts
    272
    Quote Originally Posted by Welshgasman View Post
    All I could think of is code to check with an NTP server?

    Google for VBA code to sync system time.?

    Edit:
    I have found this code that will at least check if the date and time are correct?

    https://stackoverflow.com/questions/48371398/get-date-from-internet-and-compare-to-system-clock-on-workbook-open


    Further edit:
    I never realised how simple it was to change system date and time?
    https://www.mrexcel.com/board/thread...ia-vba.252042/

    So now you should be good to go?

    HTH
    Let me check it out and see how it goes

  4. #4
    Emmanuel is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2020
    Posts
    272
    Quote Originally Posted by Welshgasman View Post
    All I could think of is code to check with an NTP server?

    Google for VBA code to sync system time.?

    Edit:
    I have found this code that will at least check if the date and time are correct?

    https://stackoverflow.com/questions/48371398/get-date-from-internet-and-compare-to-system-clock-on-workbook-open


    Further edit:
    I never realised how simple it was to change system date and time?
    https://www.mrexcel.com/board/thread...ia-vba.252042/

    So now you should be good to go?

    HTH

    The links seems to be for an excel database
    Will it also work on access database?

  5. #5
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,121
    Hi Paul
    Seems you had more success than me when googling.
    However, the SO link appears to be incorrect. Please could you recheck it

    EDIT
    The SO link has a missing : a place after https. This should work excel - Get Date from Internet and compare to System Clock on Workbook Open - Stack Overflow
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,258
    No idea as to how that happened, as the site puts that in?
    The link works now anyway?

    @Emmanuel, I see no reason why not. I just tested all that code in a test DB of mine and it said my clock was OK. Then I tested the Date and Time functions and that worked as well?
    I was expecting complicated API calls to do those.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  7. #7
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,121
    Thanks Paul
    All the methods I had found did involve complex code. This is much simpler.
    I also hadn't realised how easy it was to reset system time using VBA.
    Instead of the two Serial functions, you can also use standard date/time values e.g. Date=#9/25/2018# & Time=#6:35:24 PM#

    That does of course mean that testing against internet time when an Access app is opened is only of limited use in terms of security.
    Nothing to stop a user changing the date after the initial check was done ... though it would work for say apps supplied with a 30 day evaluation period.
    Much simpler than the code I used for this purpose in one of my commercial apps
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  8. #8
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,121
    Just a quick comment to say code to change the system clock date/time will only work when Access is run as an administrator

    The attached app combines both sets of code, adds error trapping together with an extra procedure to reset the system clock datetime to internet datetime (allowing for daylight saving)
    Attached Files Attached Files
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  9. #9
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,258
    Ah, yes, I run my computer as an administrator.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  10. #10
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,121
    So do I...but do you run Access as an administrator?
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  11. #11
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,258
    Quote Originally Posted by isladogs View Post
    So do I...but do you run Access as an administrator?
    Colin,
    I just open Access on my computers? I have never selected any level to open access, (or least remember doing so ), in fact I did not realise there was that option?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  12. #12
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,121
    Hi Paul

    Run as Administrator is an option when you right click on various programs. For example on my PC using Access 365:

    Click image for larger version. 

Name:	Capture.PNG 
Views:	19 
Size:	14.7 KB 
ID:	45541

    Most of the time it isn't needed in Access. However, it provides elevated permissions to do things using VBA like editing the HKLM hive of the registry, change the system date/time etc.

    Try running the ChangeClockDate or ChangeClockTime procedures (or do both together using ChangeSystemClockDateTime) using the updated file I've attached here.

    First of all try to do so with Access opened normally. You will get error 70 - permission denied.
    Repeat with Access using Run As Administrator. Those procedures will then work. Use ResetSystemClockDateTime to reverse the changes

    UPDATE
    The Access 2007 shortcut does NOT include the Run As Administrator option by default but this can be overcome.
    See How do I run Access as an Administrator? - TechRepublic
    Attached Files Attached Files
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  13. #13
    Emmanuel is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2020
    Posts
    272
    Quote Originally Posted by isladogs View Post
    Run as Administrator is an option when you right click on various programs. Most of the time it isn't needed in Access. However, it provides elevated permissions to do things using VBA like editing the HKLM hive of the registry, change the system date/time etc.

    Try running the ChangeClockDate or ChangeClockTime procedures (or do both together using ChangeSystemClockDateTime) using the updated file I've attached here.

    First of all try to do so with Access opened normally. You will get error 70 - permission denied.
    Repeat with Access using Run As Administrator. Those procedures will then work. Use ResetSystemClockDateTime to reverse the changes
    let me have a look at you db and get back to you

  14. #14
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,121
    Hi @Emmanuel
    My reply was mainly directed to @Welshgasman and I have edited it since your reply.
    Anyway, hopefully you can make use of it for your purposes
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  15. #15
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,258
    Ah, OK, I have used that option for other programs in the past, but never Access. Mainly the DOS command window.

    Quote Originally Posted by isladogs View Post
    Hi Paul

    Run as Administrator is an option when you right click on various programs. For example on my PC using Access 365:

    Click image for larger version. 

Name:	Capture.PNG 
Views:	19 
Size:	14.7 KB 
ID:	45541

    Most of the time it isn't needed in Access. However, it provides elevated permissions to do things using VBA like editing the HKLM hive of the registry, change the system date/time etc.

    Try running the ChangeClockDate or ChangeClockTime procedures (or do both together using ChangeSystemClockDateTime) using the updated file I've attached here.

    First of all try to do so with Access opened normally. You will get error 70 - permission denied.
    Repeat with Access using Run As Administrator. Those procedures will then work. Use ResetSystemClockDateTime to reverse the changes

    UPDATE
    The Access 2007 shortcut does NOT include the Run As Administrator option by default but this can be overcome.
    See How do I run Access as an Administrator? - TechRepublic
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 12-05-2019, 04:18 PM
  2. Replies: 11
    Last Post: 12-04-2017, 07:18 AM
  3. Replies: 6
    Last Post: 03-02-2016, 12:58 PM
  4. Replies: 5
    Last Post: 04-11-2015, 03:54 AM
  5. Can System Restore correct Form Size issue
    By fordtough in forum Forms
    Replies: 0
    Last Post: 04-12-2011, 02:56 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums