Combobox value makes filed visible

dan231

Registered User.
Local time
Today, 16:20
Joined
Jan 8, 2008
Messages
158
I am having trouble with this.

I have a combobox that you can select: Class 1, Class 2 or Class 3
When you select Class 1, I want a check box turned visible.

I have tried various If stmts:
Private Sub Combo33_Enter()
If Combo33 = "Class 1" Then
txtClass1.Value = True
Else
txtClass1.Value = False
End If
End Sub

I have also tried after update, on change, etc.

I am missing something, but I can't seem to find it.
 
Try using .visible = true or false instead of .value.
 
I'm sorry, that is what I meant.
 
Should this not be the 'after update' event?
 
I am missing something, but I can't seem to find it.
Well, for one I think you think the ENTER event is something that it isn't. This is just one that is just before GOT FOCUS, not using the Enter key.
 
That doesn't work either.
My thinking is that there is something wrong with:
If Combo33 = "Class 1" Then
 
what is the row source for your combo box? Right now, if the bound column doesn't contain "Class 1" then the criteria isn't met.

Make sure that you have the correct column bound, or switch the code to read:

Combo33.column(x) =

Where x is the column number....just remember that the numbering starts at 0
 
That doesn't work either.
My thinking is that there is something wrong with:
If Combo33 = "Class 1" Then

Could easily be as it returnes the key :

Try this
Before the IF clause
Debug.print Combo33
 
what is the row source for your combo box? Right now, if the bound column doesn't contain "Class 1" then the criteria isn't met.

Make sure that you have the correct column bound, or switch the code to read:

Combo33.column(x) =

Where x is the column number....just remember that the numbering starts at 0

Awesome! That did it. I had never heard/seen that before.
Thank you!
 
The test worked wonderfully, but not at all in the real environment.

This is for a student db. The student is signed up for a range of class programs. Each program has certain classes. I had it setup with conditional formatting, but it was super buggy (refreshing all the time, which I find out now is a bug).

I took out the formatting but still need a way to highlight each class in the program.

I have a box around each class an dam trying to either turn it visible or change the background of it when the combo box show the program name. I applied the above help to this form and it is not working.

here is the code section:
Code:
Private Sub CourseEnrollment_AfterUpdate()
If CourseEnrollment.Column(1) = "Residential Inspector Multi-Discipline" Then
    Option34.Value = True
    BoxExamPrep.Visible = True
    Option38.Value = True
    Option42.Value = True
    Option46.Value = True
    Option50.Value = True
    Option54.Value = True

Refresh

ElseIf CourseEnrollment = "Residential Inspector - Mechanical" Then
    Option34.Value = True
         Option38.Value = True
    Option42.Value = True
Refresh

ElseIf CourseEnrollment = "Residential Inspector - Plumbing" Then
    Option34.Value = True
         Option38.Value = True
    Option46.Value = True
Refresh

ElseIf CourseEnrollment = "Residential Inspector - Electrical" Then
    Option34.Value = True
    Option38.Value = True
    Option50.Value = True
Refresh

ElseIf CourseEnrollment = "Residential Inspector - Plan Review" Then
    Option34.Value = True
         Option38.Value = True
    Option54.Value = True
Refresh
    
ElseIf CourseEnrollment = "Property Maintenance Inspector" Then
    Option34.Value = True
         Option38.Value = True
    Option70.Value = True
Refresh
    
ElseIf CourseEnrollment = "Commercial Building Inspector" Then
    Option34.Value = True
         Option74.Value = True
Refresh

ElseIf CourseEnrollment = "Commercial Mechanical Inspector" Then
    Option34.Value = True
         Option78.Value = True
    Option82.Value = True
    Option86.Value = True
Refresh
    
ElseIf CourseEnrollment = "Illinois Commercial Plumbing Inspector" Then
    Option62.Value = True
    Option66.Value = True
    Option86.Value = True
Refresh

Else
    Option34.Value = False
    BoxExamPrep.Visible = False
    Option38.Value = False
    Option42.Value = False
    Option46.Value = False
    Option50.Value = False
    Option54.Value = False
    Option66.Value = False
    Option70.Value = False
    Option74.Value = False
    Option78.Value = False
    Option82.Value = False
    Option86.Value = False
    
End If

    
End Sub

Currently I have the box set to Normal with Yellow background and not visible. I thought this would be a no brainer based on the test from yesterday.
 
would it be possible for you to post the db? You can strip out any sensative data. Also, if you are using A2007, please save it as a MDB file, as not everybody uses A2007.

Just noticed....the first part of the If you specify the column number..but in the elseif sections you dont.

I personally would use a Select Case Statement. Also, I would check the ID number of the combo box (You are using a separate table with ID numbers for the combo box row source correct?)
 
I did get it to work using the event on the form:

Private Sub Form_Current()
If CourseEnrollment = "Residential Inspector Multi-Discipline" Then
Me.BoxExamPrep.Visible = True
Else
Me.BoxExamPrep.Visible = False
End If
End Sub

Which does seem to be working.
I don't know the case stmts at all, so I haven't used them yet.
 
What a Select Case statement does:

A value is choosen to compare to a series of conditions. So, for example:

Select Case me.CourseEnrollment.column(1)

means that Access is going to use the value of the second column in the control CourseEnrollment found on the current object (Your form)

then you tell Access what you want to happen when the value meets each criteria.

Case 1
Do what you want
Case 2
Do what you want
Case 3
Do what you want
Case Else
Do what you want when no other case fits
End Select

Once a Case criteria is met, it will execute the code for that case. It will then stop evaluating the case and jump to the end of the select statement.
 
So the 1 in Case 1 represents CourseEnrollment = " "?
 
the syntax for Case is:

Case [Value you want to equal to]

Here is an example. Lets say that me.ComboBox has 7 entries. One entry for each day of the week, starting on Sunday. There are two columns. The first is an ID number, the second is the day:

Code:
Select Cast me.ComboBox 
 Case 1
   msgbox "You have Selected Sunday"
Case 2
   msgbox "You have Selected Monday"
Case 3
  msgbox "You have Selected Tuesday"
Case 4
  msgbox "You have Selected Wednesday"
Case 5
  Msgbox "You have Selected Thrusday"
Case 6
  msgbox "You have Selected Friday"
Case 7
  msgbox "YOu have selected Saturday"
Case Else
  Msgbox "Not a valid Day of the Week"
End Select

now, if you wanted to test against the second column, which would be the actual day, it would look like this:

Case "Sunday"
msgbox "It's Sunday...Watch Football!"
 
Ug, the case is not working

Code:
Private Sub Form_Current()

Select Case Me.CourseEnrollment.Column(1)

    Case "Residential Inspector Multi-Discipline"
         BoxExamPrep.Visible = True
         BoxBldg.Visible = True
         BoxMech.Visible = True
         BoxPlmb.Visible = True
         BoxElct.Visible = True
         BoxPR.Visible = True
         
    Case "Property Maintenance Inspector"
        BoxExamPrep.Visible = True
        BoxIntlProp.Visible = True
        BoxBldg.Visible = True
        
    Case "Commercial Building Inspector"
        BoxExamPrep.Visible = True
        BoxIntlBldg.Visible = True
    
    Case "Commercial Mechanical Inspector"
        BoxExamPrep.Visible = True
        BoxIntlMech.Visible = True
        BoxIntlMechPR.Visible = True
        BocIntlFuel.Visible = True
        
    Case "Illinois Commercial Plumbing Inspector"
        BoxPlbCode.Visible = True
        BoxIntlFuel.Visible = True
        BoxPlmbPR.Visible = True
        
    Case "Permit Technician"
        BoxExamPrep.Visible = True
        BoxIntlBldPt1.Visible = True
        BoxIntlBldPt5.Visible = True
        BoxZoning.Visible = True
        
    Case "Residential Inspector - Mechanical"
        Me.BoxExamPrep.Visible = True
        BoxBldg.Visible = True
        BoxMech.Visible = True
        
    Case "Residential Inspector - Plumbing"
        BoxExamPrep.Visible = True
        BoxBldg.Visible = True
        BoxPlmb.Visible = True
        
    Case "Residential Inspector - Electrical"
        BoxExamPrep.Visible = True
        BoxBldg.Visible = True
        BoxElct.Visible = True
        
    Case "Residential Inspector - Plan Review"
        BoxExamPrep.Visible = True
        BoxBldg.Visible = True
        BoxPR.Visible = True
    
    Case Else
         BoxExamPrep.Visible = False
         BoxBldg.Visible = False
         BoxMech.Visible = False
         BoxPlmb.Visible = False
         BoxElct.Visible = False
         BoxPR.Visible = False
         BoxBldg.Visible = False
         BoxMech.Visible = False
        
    End Select
End Sub
 
EDIT: I just changed:
Select Case Me.CourseEnrollment.Column(1)
to .Column(0) and it works.
 
EDIT: I just changed:
Select Case Me.CourseEnrollment.Column(1)
to .Column(0) and it works.

If the bound column is the first column then you don't even need that. You could just use

Select Case Me.CourseEnrollment
 
OK, good to know.

The case stmt seems very easy and it's less work :)

Thank you for your help.
 

Users who are viewing this thread

Back
Top Bottom