Results 1 to 9 of 9
  1. #1
    xopherira is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2015
    Location
    Indiana
    Posts
    53

    Pass combo box selection to docmd.runsql

    How do you use a combobox selection as a variable for runSql? I would like to be able to make a selection and have the field chosen from comboBox be the input for "comboBox_selection" in sql command.


    Code:
    DoCmd.RunSQL ("ALTER TABLE comboBox_selection " & "ADD keyColumn COUNTER;")


  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
    You would normally design your tables and fields based on your business requirements. One would not expect to have to add fields to table via a form (especially an autonumber field) during operations.

    Tell us more about your business requirement.

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    you wouldnt. normally youd put the parameters in a query and run the query via docmd.openquery myquery

  4. #4
    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
    You wouldn't (perhaps 1 time in 10000) be using an Alter statement to modify a table design to add an autonumber field into an operational database.

    You might use a development database and test something, but this is NOT A NORMAL PROCEDURE. In test or development you would create the table with a utility or manually.

  5. #5
    xopherira is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2015
    Location
    Indiana
    Posts
    53
    The problem is i am loading an excel template. I need to add a key field to template and delete before the export. This all needs to be done behind the scene without interaction from user in terms of the user not modifying the excel spreadsheet.

  6. #6
    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
    Why? Wouldn't the key be useful to the user or his/her queries etc?

    ????
    I need to add a key field to template and delete before the export.

    My gut feeling is you have not made a commitment to leave Excel, or use Access(database) as was intended.
    But you know What you're trying to accomplish better than readers do.

  7. #7
    xopherira is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2015
    Location
    Indiana
    Posts
    53
    The reason has to do with the fact I am working with leagcy process between a cutomer facing team and production team. Neither of these would need or use queries. They are going to run a tool that processes an excel spreadsheet.

  8. #8
    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
    Perhaps you could tell us more about the requirements and give us some context, and perhaps some sample data.
    How do you expect readers to get some "feel" of your application or need from
    "How do you use a combobox selection as a variable for runSql?"

    Why can't you build the tool based on your requirements? Are you trying to tell readers that your needs change with every run?


  9. #9
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Maybe something like the following is what you are asking for.
    Code:
    Dim strSQL As String
    strSQL = "ALTER TABLE " & Me.ComboBoxName.Value & " ADD keyColumn COUNTER;"
    
    CurrentDb.Execute strSQL, dbFailOnError

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

Similar Threads

  1. Queries vs VBA DoCmd.RunSQL
    By ck4794 in forum Programming
    Replies: 1
    Last Post: 10-27-2013, 10:31 AM
  2. DoCmd.RunSQL
    By Access_Blaster in forum Programming
    Replies: 6
    Last Post: 07-23-2013, 09:27 PM
  3. my first DoCmd.RunSQL
    By broecher in forum Programming
    Replies: 4
    Last Post: 11-05-2010, 09:35 PM
  4. Problem with DoCmd.RunSQL
    By Peter01 in forum Programming
    Replies: 2
    Last Post: 09-10-2009, 07:11 PM
  5. docmd.runsql not working
    By Rameez in forum Programming
    Replies: 3
    Last Post: 08-07-2009, 10:07 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