Results 1 to 5 of 5
  1. #1
    bitesize910 is offline Novice
    Windows XP Access 2013 32bit
    Join Date
    Dec 2019
    Posts
    5

    How to write a code using a combo box selection as the target?

    Hi all,

    This question is fairly simple (hopefully). I'm trying to create a form that can interact with several different tables (all of which have the same fields). I'm using this to keep track of training for volunteers. I have an idea of how to write a code to input several fields into one specified table. Can I swap out the 'target' for a combo box code? That way I can select a specified table from a combo box (rather than having the one table written into the code), hit a button, and the fields would populate in that specified table. Let's say the table's names are master_log and training_log. The code of the master_log would be:

    DoCmd.RunSQL "INSERT INTO master_log VALUES ([combo0].value)"

    How would I switch out the master_log with the combo box, so I could select master_log or training_log from drop down box?

    Thanks!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Why do you have several tables with identical fields? Why not 1 table with another field to identify a category?

    Combobox would be a variable input. Concatenate variable inputs. Specify field receiving data.

    DoCmd.RunSQL "INSERT INTO master_log([fieldname]) VALUES (" & Me.[combo0] & ")"
    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
    bitesize910 is offline Novice
    Windows XP Access 2013 32bit
    Join Date
    Dec 2019
    Posts
    5
    Well, when I had originally created this database, we were trying to use it as a way to store information about our volunteers schedules/trainings throughout the year. I wanted a master log (where we could search for any one particular person's schedule to easily find them) and an individual training table. The individual tables were supposed to make it easy to see where each individual volunteer was at in their training. For some reason, I was under the impression that you had to have a table in order to create a form, however, after seeing your response and doing some more digging, I think I have found an easier way to store the individual data. But! I still used your code as a way to navigate between certain tables from one form, so thank you!

  4. #4
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,643
    The individual tables were supposed to make it easy to see where each individual volunteer was at in their training.
    I'm afraid to ask if you have seperate tables for each volunteer.

    You should have a number of tables such as a table of volunteers, a table of trainings, a table of trainings a volunteer has taken(which includes the primaryKeys from the volunteer and trainings table) If the tables are set up correctly you should be able to easily pull all the information you need from them.

    I would suggest you post a copy of your DB or a sceenshot of your relationships for comment. It will save you a world of problems in the future.

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    bitesize910,
    I agree with moke123 a copy of your database or screen shot of relationships would be useful to others, especially since the thread is marked "SOLVED". Posted solutions may help someone reading/searching the forum.

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

Similar Threads

  1. Replies: 31
    Last Post: 05-29-2017, 08:21 AM
  2. Replies: 12
    Last Post: 11-14-2014, 11:17 AM
  3. Replies: 1
    Last Post: 10-07-2014, 12:42 PM
  4. Replies: 5
    Last Post: 04-09-2014, 06:57 PM
  5. Replies: 8
    Last Post: 01-30-2012, 02:13 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