Conditional Formatting

froggiebeckie

Registered User.
Local time
Today, 07:52
Joined
Oct 11, 2002
Messages
104
I have a data entry form for test results.
The tests have some common fields, but also some unique fields.
I'm trying to have the unique fields visible/invisible, based on the type of test selected in the Test field.

I have the following code in the AfterUpdate event of the TEST field.

Code:
Private Sub Test_AfterUpdate()
If Me.Test = "3PtBend" Then
    Me.[StressAtYield(ksi)].Visible = True
    Me.[EnergyToYieldPoint(lbf-in)].Visible = True
    Me.[Modulus_2To_5(ksi)].Visible = False
    Me.[ShortBeamStrength(ksi)].Visible = False
Else
    Me.[StressAtYield(ksi)].Visible = False
    Me.[EnergyToYieldPoint(lbf-in)].Visible = False
    Me.[Modulus_2To_5(ksi)].Visible = True
    Me.[ShortBeamStrength(ksi)].Visible = True
    
End If

End Sub

It works fine as long as I don't include the 4th field [ShortBeamStrength(ksi)].
Doesn't matter whether the result is set to True or False, the code errors out with "Run-time error '438': Object doesn't support this property or method".

If I remove both the True and the False conditions for this field, the other 3 respond correctly. If I remove one or the other of the conditions, the remaining one errors out.

I've double and triple-checked the field name, even copying and pasteing directly from the form.

Any idea why this field is causing the code to error out?


Thanks in advance,
BeckieO
 
You need to refer to control names in VBA, not field names. To check your control name open the form in design view and look at the Other tab. The Name listed is your control name.

You shouldn't need the brackets at all. If you start typing Me. the intellisense should show you the available controls and methods.

On another note, you should consider getting rid of the parenthesis in your field names.
 
EternalMyrtle, you nailed it for me.
Turns out the control name had a typo, so ...strength turned into ...strenght.
Thanks for pointing me in the right direction, I don't think I'd have ever found it.

And also, thanks for the other tips.

I certainly learned a couple of things today.
 
No problem. The control name vs field name thing takes some getting used to. Rest assured that many code issues posted on here stem from that problem.

Good luck!
 

Users who are viewing this thread

Back
Top Bottom