If code for combo box column 3

stu_c

Registered User.
Local time
Today, 20:03
Joined
Sep 20, 2007
Messages
494
hi all
I have a combo box (CmbVehicleType), in the third column I have Fuel type, Diesel, Petrol Electric etc.

I want an If query that if a car is selected it looks at column 3 on the drop down list and hides/unhides fields depending on the type, I tried the following code without any luck.

Code:
If Me.CmbVehicleType.[Column](3).Value = "Electric" Then
    Me.LblPriceOfFuel.Visible = False
    Me.ChargingLeadPresent.Visible = True
    Me.BatteryServiceTimeLeft.Visible = True
Else
    Me.LblPriceOfFuel.Visible = True
    Me.ChargingLeadPresent.Visible = False
    Me.BatteryServiceTimeLeft.Visible = False

End If

Thanks in advnace
 
what does 'without any luck' mean?

column numbers start from 0, so perhaps you mean you should be using column(2)?
 
thanks for the reply,
when I mean I had no luck it was generally meaning it didn't work, that was a typo on my part even with number 2 it still didn't work

Many thanks
what does 'without any luck' mean?

column numbers start from 0, so perhaps you mean you should be using column(2)?
 
Try without the ".Value"
Code:
If Me.CmbVehicleType.[Column](2) = "Electric" Then
    Me.LblPriceOfFuel.Visible = False
    Me.ChargingLeadPresent.Visible = True
    Me.BatteryServiceTimeLeft.Visible = True
Else
    Me.LblPriceOfFuel.Visible = True
    Me.ChargingLeadPresent.Visible = False
    Me.BatteryServiceTimeLeft.Visible = False

End If
 
Perhaps get rid the the square parentheses as well?

I only have the following in one of my forms

Code:
Me.Client = Me.CMS.Column(1) & ":" & Me.CMS
Me.CaseWorker = Me.CMS.Column(2)
Me.txtDivision = Me.CMS.Column(3)
 
Perhaps get rid the the square parentheses as well?

I only have the following in one of my forms

Code:
Me.Client = Me.CMS.Column(1) & ":" & Me.CMS
Me.CaseWorker = Me.CMS.Column(2)
Me.txtDivision = Me.CMS.Column(3)
Yes, FWIW After posting my suggestion, I noticed the square brackets, which got copied. I wouldn't usually use then but it does seem to work with them.
 
'meaning it didn't work' is as unhelpful as 'had no luck'. After 300+ posts you must know by now that if we are to help you, we need to know some detail - you get an error? if so what is the error? you get a wrong result? if so what do you get, what do you expect to get? code won't compile - what is the message description, what line does it occur on? Otherwise we are wasting our time just guessing. Others have picked up some typo's which since you say 'that was a typo' takes us no further forward.
 
And are you sure that the code executed?
 
Morning
sorry for the late reply, work took over, has anyone got any suggestions as I have tried the above code without any success and is showing the error code
"run time error 450:
number of arguments or invalid property assignment"

Code:
If Me.CmbVehicleType.[Column](2) = "Electric" Then
    Me.LblPriceOfFuel.Visible = False
    Me.ChargingLeadPresent.Visible = True
    Me.BatteryServiceTimeLeft.Visible = True
Else
    Me.LblPriceOfFuel.Visible = True
    Me.ChargingLeadPresent.Visible = False
    Me.BatteryServiceTimeLeft.Visible = False

End If
 
If Me.CmbVehicleType.Column(2) = "Electric" Then
 

Users who are viewing this thread

Back
Top Bottom