Combo Box on Msg Box VBA

QandAdam

New Member
Joined
Jan 12, 2019
Messages
30
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.
 

Some videos you may like

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

xenou

MrExcel MVP, Moderator
Joined
Mar 2, 2007
Messages
16,630
Office Version
2013
Platform
Windows
A form button can run a query simply by using DoCmd.OpenQuery() as the code which runs when the button is clicked.
 

QandAdam

New Member
Joined
Jan 12, 2019
Messages
30
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:
FieldUpdate ToCriteria
StaffName[ENTER STAFF NAME]
Batch[ENTER BATCH ID]

<tbody>
</tbody>

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:

xenou

MrExcel MVP, Moderator
Joined
Mar 2, 2007
Messages
16,630
Office Version
2013
Platform
Windows
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).
 

QandAdam

New Member
Joined
Jan 12, 2019
Messages
30
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?
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
75,543
Office Version
365
Platform
Windows
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.
 

xenou

MrExcel MVP, Moderator
Joined
Mar 2, 2007
Messages
16,630
Office Version
2013
Platform
Windows
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.
 

welshgasman

Well-known Member
Joined
May 25, 2013
Messages
779
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
 

Watch MrExcel Video

Forum statistics

Threads
1,096,307
Messages
5,449,579
Members
405,573
Latest member
Diogo Martins

This Week's Hot Topics

Top