Results 1 to 13 of 13
  1. #1
    LaughingBull is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Location
    Toledo Ohio
    Posts
    143

    vba code to auto update date fields

    this is the form and the code. AppDate has a date picker and with this code after I pick a new day the other date fields don't update until I tab to the next field. I want the other date fields to automatically update after I pick a new date from the date picker in the AppDate field.
    What am I missing?



    first date Sunday field name is AppDat then Monday AppDate2 etc
    Time Sunday Monday Tuesday Wednesday Thursday Friday Saturday
    10:00 AM 07/02/17 07/03/17 07/04/17 07/05/17 07/06/17 07/07/17 07/08/17
    10:30 AM
    11:00 AM Private Sub AppDate_AfterUpdate()
    11:30 AM
    12:00 PM
    12:30 PM AppDate2 = DateAdd("d", 1, [AppDate])
    1:00 PM AppDate3 = DateAdd("d", 2, [AppDate])
    1:30 PM AppDate4 = DateAdd("d", 3, [AppDate])
    2:00 PM AppDate5 = DateAdd("d", 4, [AppDate])
    2:30 PM AppDate6 = DateAdd("d", 5, [AppDate])
    3:00 PM AppDate7 = DateAdd("d", 6, [AppDate])
    3:30 PM
    4:00 PM
    4:30 PM Me.Refresh
    5:00 PM
    5:30 PM
    6:00 PM End Sub
    6:30 PM
    7:00 PM
    7:30 PM

  2. #2
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    You would need the OnChange event which happens each time something is entered in the field. If the user doesn't use the date picker it will cause errors, if they begin by typing a 1 the event will fire.

  3. #3
    LaughingBull is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Location
    Toledo Ohio
    Posts
    143
    sometimes it update the other AppDates and sometimes it does not.

  4. #4
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Not sure what you mean by that. You could also put it in the control source of the subsequent fields: =AppDate+1, AppDate+2, etc

  5. #5
    LaughingBull is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Location
    Toledo Ohio
    Posts
    143
    Thank You I got this to work. Can you help me with a date in a text box on a form to display the name of the day the date is for. I have searched but I don't know how to apply what I found to my form. The text box is a date field with a date picker and what I want is the name of the day to be displayed in the text box after I pick a date.

  6. #6
    LaughingBull is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Location
    Toledo Ohio
    Posts
    143
    the name of the textbox is AppDate

  7. #7
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    create a table (Call it tbldays) with two columns DayID and dayofWeek

    1 Sunday
    2 Monday
    3 Tuesday etc




    If the date chosen is called DateChosen

    then Control source of AppDate could be

    Dlookup("dayofWeek","tbldays","DayID = " & Weekday ( txtDate ))

    (look up the day of the week which has the DayID of 1,2,3,4 depending on the day)

  8. #8
    LaughingBull is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Location
    Toledo Ohio
    Posts
    143
    I already have =AppDate+1 in the control source that you gave me before what should I do Now

  9. #9
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Are you hoping to put a date in appdate or the name of a day? Or both??

  10. #10
    LaughingBull is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Location
    Toledo Ohio
    Posts
    143
    I know you can attache the DB but I don't see the button to upload the file.

    Click image for larger version. 

Name:	insert into table.png 
Views:	11 
Size:	66.5 KB 
ID:	29297

  11. #11
    LaughingBull is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Location
    Toledo Ohio
    Posts
    143

  12. #12
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Use the format property: dddd will give you just the day name. Or make a custom format, see here

  13. #13
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    And set the Input Mask to "99/99/0000;0;_ " ( Note: the date picker doesn't work if you have an input mask)
    Then set the Auto Tab (Other tab) to Yes

    When the firm opens, type a 8 character date (ie 07 03 2017 - just type the numbers)

    If you edit the date (just change the day), you have to leave the text box to update the value



    BTW, EVERY code module should have
    Code:
    Option Compare Database
    Option Explicit
    as the top two lines!
    Attached Files Attached Files

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

Similar Threads

  1. Can't auto update the date.
    By Jeremy Sng in forum SQL Server
    Replies: 3
    Last Post: 02-22-2017, 08:49 PM
  2. Auto-increment fields update
    By rkalapura in forum Forms
    Replies: 3
    Last Post: 01-07-2012, 06:37 AM
  3. Auto update fields in the same table?
    By WendyCha in forum Access
    Replies: 0
    Last Post: 07-07-2011, 12:11 PM
  4. Help with auto update of fields in form
    By u0909098 in forum Forms
    Replies: 1
    Last Post: 05-12-2011, 07:16 AM
  5. Replies: 3
    Last Post: 04-14-2010, 10:07 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