Results 1 to 6 of 6
  1. #1
    jlreis28 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2012
    Posts
    4

    Performing record changes upon save

    Good afternoon.

    I am trying to create an Access 2010 db that is used for tracking assets. When the data is entered in the main form, I need it to create three additional records with all the same information as the original with two changes. The DeviceID field (number) needs to be incremented up 300000 for the second record, 400000 for the third, and 500000 for the fourth. The second change is to a text field. I need to insert /tray1, /tray2, /tray3, /tray4 to the Command (text) field, one for each record.



    I've tried using some of the code to create duplicate records but have yet to make it work even remotely correctly. I thought about using an append query to add all the data in to three additional tables but haven't been able to figure out a way to modify the data in the two fields I need changed. As my VBA and Access skills need some serious upgrading, I thought I would post and see if any one had an easy idea or two on how to make this work.

    Thanks and I hope everyone has a great day.
    Justin

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    Run an UPDATE query in a Loop structure. Something like:

    DoCmd.RunCommand acCommandSaveRecord
    For i = 1 to 3
    CurrentDb.Execute "INSERT INTO tablename(<whatever fieldnames you want>, DeviceID, field2) VALUES(" & <concatenate data from form> & ", " & Choose(i,3,4,5) & "00000, '/tray" & Choose(i,2,3,4) & "')"
    Next
    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
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848
    It might be helpful if you showed us your tables and relationships as a jpg.

    There is a data model for IT Asset Inventory here
    http://www.databaseanswers.org/data_...sets/index.htm

  4. #4
    jlreis28 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2012
    Posts
    4
    Good morning and thanks for the replies.

    The database is fairly simple, just made to inventory printers and some commands. It needs to associate four device ID's for every printer (DeviceID), each ID represents a tray (DefaultCommand). The goal is to be able to output an Excel file of the devices, each line represents the DeviceID with the correctly associated tray. But as I said before, it has been a long time since I've done anything in Access or VBA and it is making this a painful process.
    Click image for larger version. 

Name:	DBDesign.jpg 
Views:	10 
Size:	21.9 KB 
ID:	7357

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    So tblDevice appears to show 4 fields. If that is the case then the relationship is 1 to 1 with tblDeviceMain and might as well just have both tables in one table. If you want 4 records in tblDevice for every record in tblDeviceMain, structure needs to be:

    tblDevice
    RecordID (PK)
    MainRecID (FK)
    DeviceID (up to 4 records for each MainRecID)
    DefaultCommandID (FK)

    tblDefCmd
    RecordID (PK)
    Command
    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.

  6. #6
    jlreis28 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2012
    Posts
    4
    Thanks. I gave up and made four tables, populated by queries, then ran an append query to combine everything. It isn't the cleanest way to do this but it is getting the job done. There is only going to be about 1000 records and this is a one-time use program.

    Thank you to everyone who replied.

    Justin

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

Similar Threads

  1. Performing calculations from a drop down list
    By snowdrop in forum Queries
    Replies: 5
    Last Post: 01-11-2012, 06:39 AM
  2. Performing calculations in the form.
    By mulefeathers in forum Forms
    Replies: 4
    Last Post: 12-07-2011, 10:47 AM
  3. Duplicate Record Cannot Save
    By magicscreen in forum Programming
    Replies: 2
    Last Post: 09-15-2010, 08:15 AM
  4. Performing count in VBA
    By jgelpi16 in forum Programming
    Replies: 3
    Last Post: 08-21-2010, 07:41 PM
  5. Replies: 14
    Last Post: 06-03-2010, 06:03 PM

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