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

    combobox to drive select macro


    I have a combox that is being populated with a table that I created in access. I have multiple other macros in the same database and need to run based on selection from combobox. How to i link item in table to the macro i wish to run when it is selected from combobox? I have tried multiple ways and searched web but have been unable to find a solution. Any help would be greatly appreciated.

  2. #2
    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
    So combobox is on a form (you don't mean a lookup field in table)?

    Not sure I understand issue. Macro can reference combobox control on form.

    I don't use macros, only VBA.

    What have you tried and what were the results?

    Where is the macro code and where is the combobox - what forms?
    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
    xopherira is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2015
    Location
    Indiana
    Posts
    53
    I have an access database that contains one form. On that form is a combobox that is being populated by a table. I would like the table values to call a macro, which is also in same database, depending on the item selected. How do I bind the items in the table to macros?

  4. #4
    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
    Still don't understand what you want to do with the combobox selection. Don't know what you mean by 'bind the items in the table to macros'.

    A data control (textbox, combobox, listbox) can be referenced in code (macro or VBA) and the value of that control can be used to accomplish something. Example:

    DoCmd.OpenReport "report name", , , "ID=" & Me.comboboxname

    What exactly do you want to accomplish with the value from combobox?
    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
    xopherira is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2015
    Location
    Indiana
    Posts
    53
    I want the value in the combobox to call a macro. The macros are in same database. If I have item1, item2, item3 in list, i want item1 to call macro1, item2 to call macro2 and so on.

  6. #6
    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
    A 'value' does not 'call' anything (macro nor VBA). Macro and VBA can use the selected value. Selection of item in combobox can trigger event code (macro or VBA). In this case perhaps you want the AfterUpdate event. Now what do you want to happen after item is selected? I already gave you one example using VBA. Select [Event Procedure] in the event property, click the ellipsis (...) to open VBA editor and type code in the procedure. If you want the event to call a macro then put the macro name in the event property or build an embedded macro.
    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
    xopherira is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2015
    Location
    Indiana
    Posts
    53
    Thanks for the help, one last thing. I am going to use docmd.runmacro in vba, should I use case statement to determine which macro is trigged from combobox selection?

  8. #8
    nick404's Avatar
    nick404 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    May 2015
    Location
    Wisconsin
    Posts
    352
    In combo after update event do something like
    Code:
    Sub cboName AfterUpdate()
    If cboName.Value = "Item1" Then
    DoCmd.RunMacro "macro1"
    End If
    If cboName.Value = "Item2" Then
    DoCmd.RunMacro "macro2"
    End If
    ....
    End Sub
    and so on through your items.
    cboName = your Combobox's name

    You could do case statement if you wanted.
    Code:
     Sub cboName AfterUpdate()
    Select Case cboName.Value
         Case "Item1"
              DoCmd.RunMacro "macro1"
         Case "Item2"
              DoCmd.RunMacro "macro2"
    .....
    End Select
    End Sub
    Last edited by nick404; 07-30-2015 at 12:23 PM. Reason: added case statement

  9. #9
    xopherira is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2015
    Location
    Indiana
    Posts
    53
    nick404, I followed first example and it will not trigger the macro. I added through Event, (...), then code builder. Thanks for your help

    Code:
    If mdr_bom_ComboBox.Value = "3ABD" Then
        DoCmd.RunMacro "3ABD_BOM_Load_Template"
        ElseIf mdr_bom_ComboBox.Value = "Fan" Then
        DoCmd.RunMacro "Fan_BOM_Load_Template"
        End If

  10. #10
    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
    What exactly does macro do? If you are already using VBA, why not put all into VBA? Why use macros? Simpler code:

    DoCmd.RunMacro Me.mdr_bom_ComboBox & "_BOM_Load_Template"
    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.

  11. #11
    xopherira is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2015
    Location
    Indiana
    Posts
    53
    Got it fixed, needed to use key value and not text value in order to trigger. How do I mark as solved?

    Thanks june and nick404.

  12. #12
    nick404's Avatar
    nick404 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    May 2015
    Location
    Wisconsin
    Posts
    352
    Is it in the combo boxes after update?

  13. #13
    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
    Thread Tools dropdown above first 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.

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

Similar Threads

  1. Select File from Computer and Save to Shared Drive
    By sgrimmer in forum Import/Export Data
    Replies: 4
    Last Post: 11-02-2015, 03:43 PM
  2. need code to copy one file from C drive to E drive
    By ChuckRS in forum Programming
    Replies: 5
    Last Post: 02-23-2015, 07:27 AM
  3. Not able to select from combobox
    By Triel in forum Forms
    Replies: 19
    Last Post: 09-26-2014, 03:51 PM
  4. Select... in combobox
    By gemadan96 in forum Forms
    Replies: 1
    Last Post: 06-03-2014, 03:51 PM
  5. Replies: 1
    Last Post: 09-07-2012, 10:48 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