Results 1 to 3 of 3
  1. #1
    jbd83 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2014
    Posts
    1

    Referencing a subform using a string variable in sql/vba

    I have a form with several subforms embedded. The user can select which subform is shown by selecting the name of the subform from a combobox.
    I want to have a button to run some vba to update the table on which the visible subform is based, which has the same name as the subform, with the value of a textbox elsewhere on the form.

    At the moment I have:



    Code:
    db.Execute "UPDATE table_to_update SET [" & table_to_update &  "].[Project] = """ & Text89.Value & """ WHERE [" &  table_to_update & "].[ID] = " & Forms!T_entity.T_Conflict.Form.ID
    Where the string table_to_update is successfully set as the combobox value earlier in the code.

    I am a bit lost both when it comes to referencing subforms and sql in vba and would really appreciate any help!

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Concatenation of the table variable is not correct.

    db.Execute "UPDATE [" & table_to_update & "] SET Project = '" & Me.Text89 & "' WHERE ID = " & Forms!T_entity.T_Conflict.Form.ID
    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. Replies: 3
    Last Post: 05-28-2013, 12:53 PM
  2. Referencing a textbox using variable values from a function?
    By omahadivision in forum Programming
    Replies: 3
    Last Post: 12-20-2012, 09:23 AM
  3. Extract Value from Variable in String
    By nguyenak in forum Programming
    Replies: 3
    Last Post: 05-24-2012, 03:50 PM
  4. Replies: 3
    Last Post: 10-15-2010, 11:17 AM
  5. Using a string variable to specify a control
    By Gerry in forum Programming
    Replies: 3
    Last Post: 04-14-2010, 02:28 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