Results 1 to 6 of 6
  1. #1
    templeowls is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    305

    Update textbox to current date via VBA

    Bit of an odd one....on my main form, I have a textbox to display the date when the DB was last updated. Every time I update the DB, I have to manually change that date to today's date.



    Is there a way via VBA and a command that, when the command is pressed, it just updates the date to today's date? I can't use the 'date' or 'now' function because then it will always show today's date and not the last updated date.

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    So you just populate the the textbox wirh Date() via you command button?

    It is not going to update each time, as it is not a control source?, you activate it with your command button.

    Might want to google and see if you can run that code just before the application closes?

    Could have it on an autoexec, but no guarantee DB would be updated?
    Last edited by Welshgasman; 02-28-2023 at 09:00 AM.
    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
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    Add date to the update query, or update event

  4. #4
    templeowls is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    305
    Quote Originally Posted by Welshgasman View Post
    So you just populate the the textbox wirh Date() via you command button?
    No, so the textbox simply has a raw date in the control source (i.e. right now it is: ='2/10/2023')

    As such, I need to manually open the form in design view and change that date to whatever today's date is when I update the DB.

    I was hoping to use VBA to be able to update that date via a command.

  5. #5
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Store it a "system table" that has other system related data in it.
    It can be completely un-normalised, it's just for your use as a developer.

    Then look it up when you need it, and set it in the table from wherever you need in the code.

    I have a "make production" routine that does a load of house keeping for the database I'm working in.
    I hide certain tables, set the toolbar off, update version numbers, set the database updated date, relink SQL views with the correct indexes set to enable them to be editable if I've switched from a development backend etc. etc.
    All in one sub that I manually call once that dev session is finished.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  6. #6
    templeowls is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    305
    I'll try that. Thanks Minty!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 8
    Last Post: 12-12-2019, 12:18 PM
  2. After Update / Populate current date
    By Eric2013 in forum Forms
    Replies: 3
    Last Post: 01-29-2015, 08:33 PM
  3. Replies: 8
    Last Post: 11-19-2012, 09:22 AM
  4. Check dosent update current date
    By bsunuwar in forum Access
    Replies: 10
    Last Post: 03-23-2011, 09:46 PM
  5. Set textbox field to depend on current date
    By lilanngel in forum Queries
    Replies: 6
    Last Post: 03-10-2011, 08:16 AM

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