Results 1 to 4 of 4
  1. #1
    BShick5088 is offline Novice
    Windows XP Access 2007
    Join Date
    May 2013
    Posts
    2

    Copy Record data into Two Tables

    Hi,



    I have a hand-me-down DB that tracks project data for our company and I need help to push a date entered on one form attached to a table into a different table. My thinking was to add VB code to the "After Update" on the field that would then push the date entered into the Master table record with the same project number. This is bacause the DB was built as several different department specific tables using the ProjectID as a primary key and the frmStatus page is based on the tblMain where all the main data should be kept.

    Let's say I have a table called tblReproduction with a date filed called txtCompletionDt, what I need to do is after the date has been entered push a copy of that date over to the tblMaster into the ProjectCompleted field, so it will show up on the reports as a completed project.

    It sounds like there should be an easy way to do this in the VBA behind the form, I just can't seem to find a good example?

    Thanks....!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    No good example because saving data dependent on other data is generally considered bad practice.

    The AfterUpdate event of txtCompletionDt would work. But what if user aborted all data entry/edit for that record? Now the entry in tblMaster is not correct. Try instead the AfterUpdate event of the form. When tblReproduction record is committed the update to tblMaster will take place.

    CurrentDb.Execute "UPDATE tblMaster SET ProjectCompleted = #" & Me!txtCompletionDt & "#"
    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.

  3. #3
    BShick5088 is offline Novice
    Windows XP Access 2007
    Join Date
    May 2013
    Posts
    2
    CurrentDb.Execute "UPDATE tblMaster SET ProjectCompleted = #" & Me!txtCompletionDt & "#"[/QUOTE]

    I don't quite understand how the # was able to work and pipe in the project number, but it does...

    Thank you Soooo much...!
    That did the trick.
    You are so cool...!

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Ooops, my suggestion was incomplete and should not have worked properly.

    The # is just to delimit a date type value. The code actually should have updated EVERY SINGLE RECORD in tblMaster because I forgot to show the WHERE clause.

    CurrentDb.Execute "UPDATE tblMaster SET ProjectCompleted = #" & Me!txtCompletionDt & "# WHERE ProjectID=" & Me!ProjectID
    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.

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

Similar Threads

  1. Replies: 3
    Last Post: 03-05-2013, 05:14 AM
  2. Replies: 5
    Last Post: 05-14-2012, 02:01 PM
  3. Replies: 1
    Last Post: 07-25-2011, 09:41 AM
  4. Copy old record data to new record
    By Aussie58 in forum Access
    Replies: 12
    Last Post: 07-20-2011, 02:30 PM
  5. Copy data from Tables in VBA
    By MattyT in forum Programming
    Replies: 4
    Last Post: 12-24-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