Fix Run-Time Error

  • Thread starter pushrodengine via AccessMonster.com
  • Start date
P

pushrodengine via AccessMonster.com

The code below works great, except when a value is entered then deleted I get
an
error “Run-time error ‘13’ Type mismatch.

How can I fix this?


Private Sub ControlsSetup()

With Me
!AddIncident.Enabled = (!Type = "Check The Welfare" Or !Type = "Dry
Run")
!Date.Enabled = (!Type = "Check The Welfare")
!Medic.Enabled = (!Type = "Check The Welfare" Or !Type = "Dry Run")
!Time1008.Enabled = (!Type = "Check The Welfare")
!Time1097.Enabled = (!Type = "Check The Welfare")
!Time1148.Enabled = (!Type = "Dry Run")
!Time1098.Enabled = (!Type = "Dry Run")
End With

End Sub

Thank you
 
A

Allen Browne

If the Type control is Null, the expression:
(!Type = "Check The Welfare" Or !Type = "Dry Run")
evaluates to Null. Your attempt to assign Null to the Enabled property of
AddIncident will then fail.

Try:
!AddIncident.Enabled = Nz((![Type] = "Check The Welfare" Or ![Type] =
"Dry Run"), False)
and so on for the following lines.

Can I also suggest caution in choosing field names? Date is a reserved word
in both SQL and VBA, and fields have a Type property. You will get away with
it in this particular case, but it will cause you grief sooner or later. For
a list of the names to avoid, see:
http://allenbrowne.com/AppIssueBadWord.html
 
Top