Results 1 to 8 of 8
  1. #1
    NateH is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2016
    Posts
    5

    Using a user-selected table to populate fields in a form

    I have "inherited" an Access database. It has hundreds of tables, all with the exact same fields. And hundreds of forms, one for each table. Eventually, I plan to get it down to one table and one form, but for now, I'd like to create a form that allows the users of this database to access any one of the tables, but this has thus far proved to be a bit trickier than I thought it'd be.

    First, I thought I'd set up a Combo Box within the form that feeds information to the Record Source. But that didn't work.



    So then I created a form that simply asks which table the user wants to use, then opens the other form, feeding it the selected table. But that didn't work either.

    Anyone have any suggestion of how I go about doing this? I should note that I am fairly new to Access.

  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,652
    Getting rid of all the tables is certainly the goal. In the meantime, your second idea should work, presuming the combo has a list of form names:

    DoCmd.OpenForm Me.ComboName
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,441
    do all the identical tables have a similar naming convention and are they all identifiable by name from anything else in the database?

    ie.e

    tblSupportTable1
    tblSupportTable2
    tblIdenticalTable1
    tblIdenticalTable2
    tblIdenticalTable3
    ..
    tblIdenticalTable100

    If you have a reliable naming convention listing all the tables that meet a criteria in a list box or combo box is pretty easy, then it's just a matter of changing the record source for the form based on the selected table.

  4. #4
    NateH is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2016
    Posts
    5
    About two-thirds of the tables seem to adhere to one naming convention pretty well. About half of the rest adhere to what appears to be a separate naming convention. Which leaves about a sixth of the tables that appear to be named on a whim.

    Nate

  5. #5
    NateH is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2016
    Posts
    5
    OK, so I entered "DoCMD.OpenForm Me.Combo0" (without the quotes) as the Record Source on the form's property sheet, but I'm getting an error message that says "The record source 'DoCMD.OpenForm Me.Combo0' specified on this report or form does not exist.

    What am I doing wrong?

    Thanks,
    Nate

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    That was VBA code to be placed behind a button. The user would make their selection in the combo, then click the button.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,441
    OK take it a step further, with VBA, with vba you could.

    1. Scan all tables in your database
    2. Look at the structure of each table, if it meets a certain criteria (the tables you're interested in) append that list to a list box or other control so you could view the list of tables.
    IF *ALL* the tables in the database are identically structured this is much easier and you don't need to examine the structure to see if they can be a 'valid' data source.
    3. After selecting the table click a butotn (or other event) to change the record source of the form
    4. Requery the form with the new record source

    and it should work

    this is a very short description but likely the steps you'll want to follow.

  8. #8
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,441
    Simple example because I was bored and thought this looked fun!

    NateH.zip

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

Similar Threads

  1. Replies: 4
    Last Post: 04-04-2016, 08:11 AM
  2. Replies: 6
    Last Post: 06-23-2015, 06:58 PM
  3. Replies: 3
    Last Post: 02-16-2015, 08:28 AM
  4. Replies: 3
    Last Post: 12-23-2013, 02:14 PM
  5. Replies: 0
    Last Post: 03-08-2011, 05:56 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