Results 1 to 4 of 4
  1. #1
    degras is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Nov 2010
    Posts
    72

    Populate table/subform from VBA

    I have a form for workers and it contains a subform for scores representing a row from a workers skills matrix. These scores are stored in a separate table, one record per skill per worker. When a new worker record is created I would like to populate the scores table with default skills (with a zero score) for that worker - so that I don't have to manually create the same 50 or so skills for each worker. How from VBA can I add rows to the subform and set the skill field for each row?

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    I wouldn't think about populating the subform, I'd think about populating the underlying table. You could use an append query that got the worker value from the form and the skills from their table:

    INSERT INTO TableName(Worker, Skill, Score)
    SELECT Forms!FormName.Worker, Skill, 0
    FROM SkillsTable

    Then requery the subform and they should show up.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    degras is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Nov 2010
    Posts
    72
    Quote Originally Posted by pbaldy View Post
    I wouldn't think about populating the subform, I'd think about populating the underlying table. You could use an append query that got the worker value from the form and the skills from their table:

    INSERT INTO TableName(Worker, Skill, Score)
    SELECT Forms!FormName.Worker, Skill, 0
    FROM SkillsTable

    Then requery the subform and they should show up.
    Wow I never knew you could put a SELECT statement in a INSERT statement.

    Thanks.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Happy to help. I typically use the VALUES clause to insert a single value, the SELECT clause for multiple values like this.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 3
    Last Post: 12-06-2010, 06:35 PM
  2. Replies: 2
    Last Post: 10-19-2010, 11:05 AM
  3. how to populate a subform from table
    By Dengkee in forum Programming
    Replies: 1
    Last Post: 10-18-2010, 08:09 AM
  4. Replies: 0
    Last Post: 05-12-2010, 10:08 PM
  5. How to populate a subform using a record set
    By new2access123 in forum Forms
    Replies: 5
    Last Post: 03-01-2010, 10:32 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