If code for combo box column 3 (1 Viewer)

stu_c

Registered User.
Local time
Today, 01:51
Joined
Sep 20, 2007
Messages
489
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
 

CJ_London

Super Moderator
Staff member
Local time
Today, 01:51
Joined
Feb 19, 2013
Messages
16,553
what does 'without any luck' mean?

column numbers start from 0, so perhaps you mean you should be using column(2)?
 

stu_c

Registered User.
Local time
Today, 01:51
Joined
Sep 20, 2007
Messages
489
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)?
 

bob fitz

AWF VIP
Local time
Today, 01:51
Joined
May 23, 2011
Messages
4,717
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
 

Gasman

Enthusiastic Amateur
Local time
Today, 01:51
Joined
Sep 21, 2011
Messages
14,048
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)
 

bob fitz

AWF VIP
Local time
Today, 01:51
Joined
May 23, 2011
Messages
4,717
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.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 01:51
Joined
Feb 19, 2013
Messages
16,553
'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.
 

Cronk

Registered User.
Local time
Today, 12:51
Joined
Jul 4, 2013
Messages
2,770
And are you sure that the code executed?
 

stu_c

Registered User.
Local time
Today, 01:51
Joined
Sep 20, 2007
Messages
489
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
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 09:51
Joined
May 7, 2009
Messages
19,169
If Me.CmbVehicleType.Column(2) = "Electric" Then
 

Users who are viewing this thread

Top Bottom