Form Coding (1 Viewer)

deehutchins

Registered User.
Local time
Today, 13:37
Joined
May 30, 2014
Messages
49
Good afternoon,

I am using Access 2010 and I have a quick question and hopefully an easy solution for coding a dropdown selection. I currently have a form that has a checkbox and a dropdown selection. I am trying to code for the checkbox, anytime any of the selection where if it is one or all are selected I would like the checkbox to auto populate. I have come pretty close to coding the form, but my only problem is that I am getting an error saying that the selection listing was not coded right. I am mostly getting flagged for the ones in red, in which I believe it is because of the / between wording, but that is how it is listed on the form. Can someone please tell how I should code the selection list in my VBA?

Here are the selection exactly how they are in the dropdown:
Training/Education/Coaching
Process Improvement
Other
Communication/Denial Language

Thanks,
 

burrina

Registered User.
Local time
Today, 15:37
Joined
May 10, 2014
Messages
972
Unclear on your criteria for the check box? You can Cycle thru your controls using the following code: Of course add your criteria to it as you wish and change to suit your form name. Otherwise a simple;


If Me.mycombobox = "somevalue" Then
Me.mycheckbox = True
End If


'Cycle through the controls
For Each ctl In frmClearedForm
'Test if they are textboxes, listboxes etc
If TypeOf ctl Is TextBox Then
'Check if it's unbound
If ctl.ControlSource = "" Then
ctl = ""
End If
End If
If TypeOf ctl Is ComboBox Or TypeOf ctl Is ListBox Then
ctl.ListIndex = 0
If TypeOf ctl Is CheckBox Then ctl.Value = False
If TypeOf ctl Is OptionButton Then ctl.Value = False
Next ctl

Hope these examples help.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 13:37
Joined
Aug 30, 2003
Messages
36,128
Might help if you show your code. I'd probably have those in a table and be using a numeric key field anyway.
 

deehutchins

Registered User.
Local time
Today, 13:37
Joined
May 30, 2014
Messages
49
Here is my current code for the form:

Private Sub Combo237_Click()
If Me.Combo237="Training/Education/Coaching"
Me.Combo237 = "Process Improvement"
Me.Combo237 = "Other"
Me.Combo237 = "Communication/Denial Language" Then
Me.Check239 = -1
Else
Me.Check239 = 0
End If
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 13:37
Joined
Aug 30, 2003
Messages
36,128
Try

Code:
If Me.Combo237="Training/Education/Coaching" OR Me.Combo237 = "Process Improvement" OR Me.Combo237 = "Other" OR Me.Combo237 = "Communication/Denial Language" Then
  Me.Check239 = -1
Else
  Me.Check239 = 0
End If
 

deehutchins

Registered User.
Local time
Today, 13:37
Joined
May 30, 2014
Messages
49
Thanks for the help it seems that it is still not working. I keep getting a run time error '13', which is a type mismatch, but I am tying the selection exactly the way it is listed.

Please help......
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 13:37
Joined
Aug 30, 2003
Messages
36,128
Are you sure the bound column of the combo is that text, rather than a numeric ID field?
 

deehutchins

Registered User.
Local time
Today, 13:37
Joined
May 30, 2014
Messages
49
Good point! Let me check and get back to you.....hopefully that might solve my problem.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 13:37
Joined
Aug 30, 2003
Messages
36,128
I would have mentioned that earlier but you said it worked sometimes.
 

deehutchins

Registered User.
Local time
Today, 13:37
Joined
May 30, 2014
Messages
49
Hey pbaldy just wanted you to know that I figured it out and thanks for the advice it worked. ;)
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 13:37
Joined
Aug 30, 2003
Messages
36,128
Happy to help!
 

Users who are viewing this thread

Top Bottom