Results 1 to 10 of 10

Thread: Combo Box on Msg Box VBA

  1. #1
    New Member
    Join Date
    Jan 2019
    Posts
    18
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Combo Box on Msg Box VBA

    I have a button which shows a Pop-Up Box asking the user to enter a name of a staff member. Is it possible to edit the Pop-Up so that instead of showing a free text box (where the user can enter anything), it shows a combo box instead which lists the staff names?

    If it helps, I currently have a query with all current staff listed. (qryCurrentStaff)

    At the moment the VBA just runs an update query and an "Enter Parameter Value" box appears to complete the missing criteria. It's a bit of a dirty way of doing things but it was the easiest when creating it.

  2. #2
    Board Regular
    Join Date
    May 2013
    Posts
    587
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Combo Box on Msg Box VBA

    You would need to create a small popup form.?
    Office 2007
    Access novice. Sometimes trying to give something back

  3. #3
    New Member
    Join Date
    Jan 2019
    Posts
    18
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Combo Box on Msg Box VBA

    Quote Originally Posted by welshgasman View Post
    You would need to create a small popup form.?
    How would I do this? The current query is an Update Query and I don't have the option to select it as the Form Data Source.

  4. #4
    MrExcel MVP
    Moderator
    xenou's Avatar
    Join Date
    Mar 2007
    Location
    Clev. OH, USA
    Posts
    16,344
    Post Thanks / Like
    Mentioned
    9 Post(s)
    Tagged
    1 Thread(s)

    Default Re: Combo Box on Msg Box VBA

    A form button can run a query simply by using DoCmd.OpenQuery() as the code which runs when the button is clicked.

    Using: Office 2010/Win7 (work) Office 2010/Win7 (home)

    You are rich in proportion to the number of things you can let alone.
    -- Henry David Thoreau

  5. #5
    New Member
    Join Date
    Jan 2019
    Posts
    18
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Combo Box on Msg Box VBA

    I have this button currently. Here's a breakdown of what the current set up is like:

    Form Button:
    Code:
    DoCmd.SetWarnings False
    DoCmd.OpenQuery "qryAllocateBatch"
    DoCmd.SetWarnings True
    qryAllocateBatch:
    Field Update To Criteria
    StaffName [ENTER STAFF NAME]
    Batch [ENTER BATCH ID]

    When the user clicks on the button, the Enter Parameter Value Box appears asking the user to [ENTER STAFF NAME] and [ENTER BACTH ID] without them actually going into the query.

    What I'm after is for the 'Enter Parameter Value' Box to display a combo box instead of free text to avoid the user spelling names incorrectly. (Or for a Msg Box to appear and do the same thing)

    Does this help clear things up?
    Last edited by QandAdam; May 7th, 2019 at 06:54 AM.

  6. #6
    MrExcel MVP
    Moderator
    xenou's Avatar
    Join Date
    Mar 2007
    Location
    Clev. OH, USA
    Posts
    16,344
    Post Thanks / Like
    Mentioned
    9 Post(s)
    Tagged
    1 Thread(s)

    Default Re: Combo Box on Msg Box VBA

    You want the combo box to be on the form before the button is clicked. I.e. 1) Choose the value(s) from the list(s). 2) Then click the button. You can't literally have the query display a combo box (it can only display the enter parameter dialog, which is what you have now).

    Using: Office 2010/Win7 (work) Office 2010/Win7 (home)

    You are rich in proportion to the number of things you can let alone.
    -- Henry David Thoreau

  7. #7
    New Member
    Join Date
    Jan 2019
    Posts
    18
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Combo Box on Msg Box VBA

    Quote Originally Posted by xenou View Post
    You want the combo box to be on the form before the button is clicked. I.e. 1) Choose the value(s) from the list(s). 2) Then click the button. You can't literally have the query display a combo box (it can only display the enter parameter dialog, which is what you have now).
    Ok, for the Form - I'm struggling to get my head around it (sorry!)

    • What would the Record Source of the Form be? I'm not able to select the current query because it's an update query.
    • What vba do I need to ensure the "Staff Name" and "Batch" Fields link to the Query fields?

  8. #8
    Board Regular Norie's Avatar
    Join Date
    Apr 2004
    Location
    Stirling, Scotland
    Posts
    74,979
    Post Thanks / Like
    Mentioned
    59 Post(s)
    Tagged
    6 Thread(s)

    Default Re: Combo Box on Msg Box VBA

    Change the UPDATE query to take the parameters from a form.

    The form itself would be unbound but would you would set the row source of the combobox on the form to a query that returns the current staff, e.g. qryCurrentStaff.
    If posting code please use code tags.

  9. #9
    MrExcel MVP
    Moderator
    xenou's Avatar
    Join Date
    Mar 2007
    Location
    Clev. OH, USA
    Posts
    16,344
    Post Thanks / Like
    Mentioned
    9 Post(s)
    Tagged
    1 Thread(s)

    Default Re: Combo Box on Msg Box VBA

    Also see here:
    http://www.databasedev.co.uk/query_filter.html

    As Norie said, for the combo box you just create the combo box with it's own row source to the data that you want to fill it in. think of it as an independent query source, not the form's query source.

    Using: Office 2010/Win7 (work) Office 2010/Win7 (home)

    You are rich in proportion to the number of things you can let alone.
    -- Henry David Thoreau

  10. #10
    Board Regular
    Join Date
    May 2013
    Posts
    587
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Combo Box on Msg Box VBA

    As mentioned, have unbound controls that have 'built in' queries as source. One for the Staff Name and possibly one for the batch ID.?
    Change the query to use the controls from the form. Use the builder to get the correct syntax.
    Have a button to run the query as you have now. The query will take it's parameters from the form and run as it used to.?

    HTH
    Office 2007
    Access novice. Sometimes trying to give something back

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •