Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    perryc is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2019
    Posts
    122

    Thumbs down Update a date and subsequent dates will be automatically updated.

    All,


    Probably need a Script for this... not sure how to write it. Any help appreciate it.

    1. Is there a way to change the first date on this query (3/14) and subsequent dates can advance accordingly? e.g. 3/14 becomes 5/10 and 3/15 will automatically becomes 5/11 and 3/16 becomes 5/12?
    Click image for larger version. 

Name:	Capture 5.10.PNG 
Views:	21 
Size:	51.0 KB 
ID:	47773

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,923
    Calculate the difference between first date and new date.
    Then update dates to date + difference
    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
    perryc is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2019
    Posts
    122
    That's sound good. But how do I write a script to update these dates? I am a very novice Access user that really don't know how to write these. Ty in advance if you or anyone can help.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,913
    So you want to pull the minimum date and increment from there? How does user decide on the date to change to? Enter into a textbox?

    CurrentDb.Execute "UPDATE tablename SET DateAssigned = DateAssigned + " & Me.tbxNewDate - DMin("DateAssigned", "tablename")

    Include filter criteria in the DMin() as well as the UPDATE if necessary.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    perryc is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2019
    Posts
    122
    1. So you want to pull the minimum date and increment from there? (yes. However, some dates are duplicated because there are different time)
    2. How does user decide on the date to change to? Enter into a textbox?
    Enter from a text box (date).

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,923
    So if you have a form, perhaps allow them to select a date from a combo list, a textbox holding the new validated date, then a button to update using June7 code.
    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
    perryc is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2019
    Posts
    122
    Your formula works perfectly. Ty soooooo much.

    I also want to update the student ID. What did I do wrong here?

    CurrentDb.Execute "UPDATE tblJtnStudentsCourses SET StudentID = me.tbxNewID"

  8. #8
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,798
    You need to concatenate references. This = me.tbxNewID" is within the quotes so it's trying to literally update StudentID to "me.tbxNewID". It might even work if that field was a text field.

    CurrentDb.Execute "UPDATE tblJtnStudentsCourses SET StudentID = " & me.tbxNewID
    If the id field is a string, more (single) quotes will be needed to encapsulate the value in me.txtNewID

    CurrentDb.Execute "UPDATE tblJtnStudentsCourses SET StudentID = ' " & me.tbxNewID & " ' "
    I added spaces so you could see them - you would not include them in your final expression.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  9. #9
    perryc is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2019
    Posts
    122
    I am so bad at this. So, how do you combine the two into just one instead?

    CurrentDb.Execute "UPDATE tblJtnStudentsCourses SET DateAssigned = DateAssigned + " & Me.tbxNewDate - DMin("DateAssigned", "tblJtnStudentsCourses")

    CurrentDb.Execute "UPDATE tblJtnStudentsCourses SET StudentID = " & Me.tbxNewID

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,913
    CurrentDb.Execute "UPDATE tblJtnStudentsCourses SET DateAssigned = DateAssigned + " & Me.tbxNewDate - DMin("DateAssigned, "tblJtnStudentsCourses") & ", StudentID = " & Me.tbxNewID

    That will update EVERY record with the same StudentID.

    I expect you need some filter criteria.

    Why would you want to change student ID? How does this impact historical records?

    I don't even see a StudentID field in that table.

    If you want to provide db for analysis, follow instructions at bottom of my post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  11. #11
    orange's Avatar
    orange is online now Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725
    @perryc

    Make sure you have a backup before doing UPDATE queries===especially if you are not familiar with SQL and/or Update.
    Update queries can be very unforgiving.

    You might consider - do a SELECT query (ReadOnly) until you confirm your criteria.
    A SELECT query with appropriate criteria should display the result you want to achieve. If you get that result, you can then switch the SELECT to an UPDATE query.

  12. #12
    perryc is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2019
    Posts
    122
    All, ty so much for your help. I have a major problem with this update. Perhaps I should give you a background first.
    What I try to do is to duplicate the template "StudentID 1" and create a new template for every new student with ID 10...11...12... (update those dates to the begin orientation date). (Student ID = Orientee ID)

    This script below changed all existing ID and dates to the new dates, which is not what I want. (I do have a backup of the backend DB).

    CurrentDb.Execute "UPDATE tblJtnStudentsCourses SET DateAssigned = DateAssigned + " & Me.tbxNewDate - DMin("DateAssigned, "tblJtnStudentsCourses") & ", StudentID = " & Me.tbxNewID

    Please help. Ty.

    Sincerely,
    Perry

  13. #13
    perryc is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2019
    Posts
    122
    Orange, I think you are absolutely correct. The query we had updated every record. I only want to update one certain StudentID for his entire schedule. I am not sure where to add the SELECT statement. Would you help?

    Background: What I try to do is to duplicate the template "StudentID 1" and create a new template for every new student with ID 10...11...12... (update those dates to the begin orientation date). (Student ID = Orientee ID)

    This script below changed all existing ID and dates to the new dates, which is not what I want. (I do have a backup of the backend DB).

    CurrentDb.Execute "UPDATE tblJtnStudentsCourses SET DateAssigned = DateAssigned + " & Me.tbxNewDate - DMin("DateAssigned, "tblJtnStudentsCourses") & ", StudentID = " & Me.tbxNewID

    Please help. Ty.

    Sincerely,
    Perry

  14. #14
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,913
    So you don't really want to change existing records. Sounds like you want to 'batch create' new set of course records for all students.

    Consider:
    Code:
    Dim intDays As Integer
    intDays = Me.tbxNewDate - Me.tbxOldDate
    CurrentDb.Execute "INSERT INTO tablename(StudentID, CourseDetails, DateAssigned, TimeBegins, TimeEnds, Instructor) " & _
                    "SELECT StudentID, CourseDetails,  DateAssigned + " & intDays & ", TimeBegins, TimeEnds, Instructor FROM tablename WHERE DateAssigned >=#" & Me.tbxOldDate & "#"
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  15. #15
    perryc is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2019
    Posts
    122
    Ty so much June7. I will try your codes after this meeting.

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

Similar Threads

  1. Replies: 1
    Last Post: 04-09-2019, 07:09 PM
  2. How to search for subsequent dates in form
    By Beeblebrox in forum Programming
    Replies: 13
    Last Post: 04-28-2016, 10:14 AM
  3. Replies: 7
    Last Post: 11-01-2013, 03:17 PM
  4. 'LastUpdated' fiedld be automatically updated
    By djclntn in forum Programming
    Replies: 8
    Last Post: 02-22-2013, 03:57 PM
  5. Trying to Automatically update date within form
    By accesskid in forum Programming
    Replies: 4
    Last Post: 04-26-2011, 07:45 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