Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Detect if there is a specific choice selected in a combo box

Posted on 2013-05-23
6
Medium Priority
?
326 Views
Last Modified: 2013-06-26
Hi.

How do I detect through vba that a specific selection has been made in a combobox in a subform? I need to send a Msgbox to the user... "You can't select this without selecting option 1 and 2 also..."

Should I use a query and then  apply it to the value "on dirty"?
0
Comment
Question by:Evert Jor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 39193062
It depends on where the code is located relative to your combo boxes, and also when you want this message to be triggered.

<< You can't select this without selecting option 1 and 2 also..>>

Also are we trying to detect choices in one or two different combo boxes?

(Your question is a little ambiguous)

If you want to run this code when a user makes a selection in a combo box on the main form, use the Before update event of your main form combo:

Private Sub cboYourMainFormCombo_BeforeUpdate(Cancel as integer)
If Me.cboYourMainFormCombo = "some value" then
      if Not(Me.SubformName.Form.Combo1 = "Value1" And Me.SubformName.Form.Combo2 = "Value2" Then
              msgbox "You cannot make this selection without first selecting Value1 and Value2"
              cancel = true
     end if
End if
End Sub

Open in new window

0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 39193229
<(Your question is a little ambiguous)>
Yes, a bit unclear...
Here I will presume that an "Option" is an actual "Option Button" (Boolean value)
...and that the two options needing to be selected together, is always the case.

Then (Pending clarification), ...another approach might be to "Disable" the combobox in the first place.
...Instead of letting them go trough all the trouble of selecting a value, (Then thinking it will work) only to find out that it wont.

Private Sub Form_Current()
    Call ValidateOptions
End Sub

Private Sub opt1_AfterUpdate()
    Call ValidateOptions
End Sub

Private Sub opt2_Click()
    Call ValidateOptions
End Sub

Private Sub ValidateOptions()
    If Me.opt1 = True And Me.opt2 = True Then
        Me.State.Enabled = True
    Else
        Me.State.Enabled = False
    End If
End Sub


Very simple sample attached
Database40.mdb
0
 

Author Comment

by:Evert Jor
ID: 39193567
Hi mbizup.

The control is in a subform and refers to a choice in another subform. Both on a main form (of course)...

Thanks so far. Regards.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 61

Accepted Solution

by:
mbizup earned 1185 total points
ID: 39193592
For code in one subform, referring to a control in another subform:

If Me.Parent.OtherChildForm.Combo1 = "xyz" Then
      ' Etc...

Open in new window

0
 

Author Comment

by:Evert Jor
ID: 39232429
boag2000:

The module you refer to in your code isn't included in your example file.
0
 

Author Closing Comment

by:Evert Jor
ID: 39279140
Thanks a lot for your help, I need to work a bit with this to get the functionality I need.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question