Results 1 to 6 of 6
  1. #1
    pdevito3 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2013
    Posts
    35

    Macros, VBA, Autopopulation of Data

    I have a request that's probably a little of the box.



    Right now, I have table 1 with (among others): ParentID (primary key), Parent Name, Daughter Count. I also have table 2 with (among others): DaughterID (primary key), ParentID, Daughter Name. Parent Name in table 1 might be W-1, daughter count might be 4, and daughter Name might be W-1A. Parent ID in table 2 is just a 1, 2, etc that has a relationship with parent ID from table 1.

    I want to have a macro that automatically populates "x" number of daughters in daughter name based off of the parent's daughter count once a field in table 1 is updated. The resepective parent ID should also populate next to each item. For example: W-1 (parent ID = 1) can make 4 daughters. Once checked it should create four 1's in parent ID of table 2 and W-1A, W-1B, W-1C, and W-1D in each of the daughter name fields.

    I have a macro that works and makes a new entry after each update, but I don't know how to change it to accomindate multiple entries based off of the field or add the appropriate alpha character. I wanted to get into VBA to try and modify the code, but the convert macro to VBA is greyed out in design mode for my macro. This is my current macro:

    If Updated("Mated") Then | Create a Record In tblTable2 | SetField | Name: tblTable2.ParentID | Value: tblTable1.ParentID | SetField | Name: tblTable2.DaughterName | Value: tblTable1.ParentName |

    Any help is greatly appreciated! Thanks

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,953
    Really should not save aggregate data, calculate when needed.

    Creating a unique custom ID (the daughter name) requires VBA code. This has been discussed often in forum. Start with https://www.accessforums.net/access/...ers-34451.html
    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
    pdevito3 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2013
    Posts
    35
    Well, the idea behind it is to elimnate manual entry. If my daughter count was 80, I don't want somebody to have to enter in a 80 values for something that could be automated. I'm thinking maybe a list form to select what I want to modify based off of now. That way it would be a one time thing and wouldn't be so reliant on the other data.


    Any other ideas?

    Thanks agian

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,953
    Not sure I understand. You want to automate creating a set of records that have an incrementing indentifier? The number of records created would be determined by some derived count? Derived from what?
    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
    pdevito3 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2013
    Posts
    35
    I want someone to enter in the parent name and number of daughters it can make (4, 10, 50, it depends on the parent) and then have some way of automating the daughter creation in another table. Whether it be some kind of button in a form, something built into the table, or something else I don't know about, I want it to be automated.

    Say I have a list of 20 parents, each with their own potential daughter count number. I want to press a button to populate the daughter table with the right parentID and the corresponding daughter name (w-1A, w-1b, etc.). Today, I made a list box with all of the parents I wanted to do this with, made a button, opened the vba code for the click event of that button, and I couldn't figure out the vba. I would think it would be a simple if clicked create a new record. Then use a for daughter count. I can't use the create a new record function unless it's a data macro in a table though, so I don't know how to approach it

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,953
    Something like:

    For i = 1 to Me.textboxCount
    CurrentDb.Execute "INSERT INTO tablename(field1, field2, field3) VALUES('" & Me.ParentID & i & "', #" & Date() & "#, " & Me.UserID & ")"
    Next

    The above shows an example of INSERT sql action for 3 field types - text, date, number.
    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. Import excel sheet data into Ms-access using VBA macros
    By gokul1242 in forum Import/Export Data
    Replies: 2
    Last Post: 10-02-2012, 04:39 AM
  2. Confusion with Data Macros and SetField
    By Datech in forum Access
    Replies: 3
    Last Post: 04-06-2012, 11:59 PM
  3. Need help with code to enable autopopulation of form
    By bacarley in forum Programming
    Replies: 1
    Last Post: 11-29-2011, 11:54 PM
  4. Autopopulation using macros?
    By EvanRosenlieb in forum Forms
    Replies: 2
    Last Post: 06-16-2011, 01:57 PM
  5. vba vs macros
    By RedGoneWILD in forum Access
    Replies: 4
    Last Post: 08-06-2010, 12:48 AM

Tags for this Thread

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