Results 1 to 7 of 7
  1. #1
    gmaster is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    May 2014
    Posts
    32

    Query from combobox


    Hi, i'm trying to write a query that reads the name chosen from a combobox and uses it to update a table with the same name (Ex. I chose "employee" from a combobox and than launch this query that makes an UPDATE instance on the "employee" tab)...i've tried with the UPDATE (=Forms![Intro]!Casellacombinata) INNER JOIN etc... but it doesn't work...Is it possible to do it??

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    No. Cannot build an Access query object with dynamic table reference. Certainly the fields would be different as well and they, too, cannot be dynamic.

    Options are:

    Many Access query objects and the code launches the one appropriate for choice.

    or

    VBA code to construct and run SQL action statement.

    What is 'employee tab'?
    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
    gmaster is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    May 2014
    Posts
    32
    Hey thanks for the answer! The employee tab was just an example, actually in the CB you can chose form a dozen tab names, each one containing different medical data of patients...
    I know a little VBA too, how'd you suggest to proceed in that case?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Why do you need to use sql UPDATE instead of data entry edit? What do you mean by 'tab'? If you want to provide db for analysis, follow instructions at bottom of my post.
    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
    gmaster is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    May 2014
    Posts
    32
    Sorry, can't provide Db... i'll try to provide a better explanation instead
    The query uses a linked Excel file that has 2 columns ("Code_number" filled the datas (code numbers, indeed) that i need to insert into a table chosen among many from a combobox, and "Id_field" with IDs that are the primary key in those tables and wich i need for the INNER JOIN) and the actual table i need to update. The DB has to take those code numbers from the Excel and put them into the chosen table (chosen from the combobox) using the INNER JOIN on the Id_field in order to put those codes in the right record, ok?
    So this is the Query i was trying to write before discovering dynamic table reference is not supported:

    UPDATE (=Forms![Intro]!Combobox1) INNER JOIN Excel ON Excel.Id_field = [=Forms![Intro]!Combobox1].Id_field SET [=Forms![Intro]!Combobox1].Code_number = Excel.Code_number;

    Intro is the name of the form where the Combobx is

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Why would the Code_number values go into different tables? Sounding like non-normalized data structure.

    Can run SQL actions in VBA. Construct the SQL with VBA. Is Code_number a text type field?

    CurrentDb.Execute "UPDATE [" & Me.Combobox1 & "] INNER JOIN Excel ON Excel.Id_field=[" & Me.Combobox1 & "].Id_field SET [" & Me.Combobox1 & "].Code_Number=[Excel].[Code_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.

  7. #7
    gmaster is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    May 2014
    Posts
    32
    Thanks a lot, works like a charm!!!

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

Similar Threads

  1. Replies: 3
    Last Post: 05-16-2013, 08:21 PM
  2. Replies: 1
    Last Post: 09-06-2011, 01:47 PM
  3. Replies: 29
    Last Post: 08-16-2011, 05:52 PM
  4. Replies: 0
    Last Post: 08-24-2010, 06:38 PM
  5. Replies: 0
    Last Post: 12-16-2009, 01:14 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