Solved

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

Posted on 2013-05-23
6
310 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
Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

 
LVL 61

Accepted Solution

by:
mbizup earned 395 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

More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

726 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