|  | Code works in one form but not in another |  | |
| | | John |  |
| Posted: Thu Sep 18, 2008 6:29 am Post subject: Code works in one form but not in another |  |
Hi
I am using the below code in one form and it works fine. I copied the same code into another form in the same app and I get a "Run-time error '2424': The expression you entered has a field, control, or property name that <my project> can not find." error. What is the problem and how can I fix it? Thanks
Regards
Dim ctl As Control
For Each ctl In Me.Controls If ctl.ControlType = acTextBox Then 'Below line gets the '2424' error If (IsNull(ctl.OldValue) And Not IsNull(ctl.Value)) Or (IsNull(ctl.Value) And Not IsNull(ctl.OldValue)) Then
End If End If Next ctl |
| |
| | | Allen Browne |  |
| Posted: Thu Sep 18, 2008 7:00 am Post subject: Re: Code works in one form but not in another |  |
| |  | |
When the error occurs, choose Debug and open the Immediate Window (Ctrl+G.) Enter: ? ctl.Name
Now you know which control it is, try: ? ctl.Value That should work, but this one will probably fail: ? ctl.OldValue
If that's the case, you have a control that has no OldValue. That could be an unbound control, or a control bound to an expression, or a control bound to a read-only field (e.g. if the form's RecordSource is a query where some fields cannot be edited.)
To fix it, modify the code to test for the conditions that could trigger the error, or use error handling to recover from the error.
-- Allen Browne - Microsoft MVP. Perth, Western Australia Tips for Access users - LINK Reply to group, rather than allenbrowne at mvps dot org.
"John" <info@nospam.infovis.co.uk> wrote in message news:uU%23khiWGJHA.4228@TK2MSFTNGP06.phx.gbl...
| Quote: | I am using the below code in one form and it works fine. I copied the same code into another form in the same app and I get a "Run-time error '2424': The expression you entered has a field, control, or property name that <my project> can not find." error. What is the problem and how can I fix it? Thanks
Dim ctl As Control
For Each ctl In Me.Controls If ctl.ControlType = acTextBox Then 'Below line gets the '2424' error If (IsNull(ctl.OldValue) And Not IsNull(ctl.Value)) Or _ (IsNull(ctl.Value) And Not IsNull(ctl.OldValue)) Then
End If End If Next ctl |
|
| |
|
|