Multiple Combo Box Access

  • Thread starter Thread starter Donuts
  • Start date Start date
D

Donuts

Hello!

I'm new to Access VBA and I need guidance on how to write the VBA code
for a form which I have created 2 combo boxes - i.e. City and Country.
The aim is to allow the user to search by selecting EITHER OR BOTH City
and Country, if both combo boxes are select a message should pop
stating that they have chosen to search by both boxes.

Thx!

Donuts
 
Check if both values are not nulls

if (NOT(isnull(combo1.Text))) AND (NOT(isnull(combo2.text))) then
msgbox "Oy, you cant have both mate!!!!!!! grrrrr, Just pick one."
else
'continue with rest of code
end

This should work
 
Sorry I misread slighly, I thought you wanted to prevent selecting both.
The code remains the same though.
You want to allow selecting both but a pop up a msg if they do.


If (NOT(isnull(combo1.Text))) AND (NOT(isnull(combo2.text))) then
msgbox "You have selected both City and Country."
' Do whatever

else
' Do summin else
endif

Put this code into a button's click event
 
You can't ever refer to the Text property of more than one control. The Text
property is only exposed when that control has the focus and only one
control can have the focus at a time. You can reference the Value property
rather than the Text property. Since the Value property is the default
property of the text or comb box, you can actually leave it off.

--
Duane Hookom
MS Access MVP


Douglas said:
Sorry I misread slighly, I thought you wanted to prevent selecting both.
The code remains the same though.
You want to allow selecting both but a pop up a msg if they do.


If (NOT(isnull(combo1.Text))) AND (NOT(isnull(combo2.text))) then
msgbox "You have selected both City and Country."
' Do whatever

else
' Do summin else
endif

Put this code into a button's click event


(e-mail address removed) (Douglas) wrote in message
http://www.ExcelForum.com/
 
Oops, sorry thats what i meant

use combo1.value

Duane Hookom said:
You can't ever refer to the Text property of more than one control. The Text
property is only exposed when that control has the focus and only one
control can have the focus at a time. You can reference the Value property
rather than the Text property. Since the Value property is the default
property of the text or comb box, you can actually leave it off.

--
Duane Hookom
MS Access MVP



http://www.ExcelForum.com/
 
Back
Top