Google
 
Webnews.only-4-geeks.com
Interesting places
news.only-4-geeks.com Forum Index » Access

Code works in one form but not in another

 
Jump to:  
 
John
PostPosted: 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
PostPosted: 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
 

Page 1 of 1 .:.

Google
 
Webnews.only-4-geeks.com

Windows Update | C++ | C | PHP | JavaScript | Photoshop | Programming | Windows 2000 | Python | Windows XP | Object | Flash | Flash - ActionScript | Paint Shop Pro | Excel | PowerPoint | Access | Word | Windows 98 | Internet Explorer 6.0 | CorelDraw12 | Java | XML | asm x86 | Linux Mandrake | Linux RedHat | Outlook |  | news from newsgroups |_ | s

Web Templates

Awesome Website Templates ©

wycieczki objazdowe Kredyty mieszkaniowe santander consumer bank baterie umywalkowe grohe artykuły biurowe Copenhague hoteles