[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2013-05-23
6
Medium Priority
?
330 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
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

834 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