By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,124 Members | 2,027 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,124 IT Pros & Developers. It's quick & easy.

Run-time error 2424 is driving me mad

P: n/a
The current event of a continuous form is:
Private Sub Form_Current()
If IsNull(me.QuoteNumber) Then
Me.quoteLetterButton.Caption = "Create quote letter"
Else
Me.quoteLetterButton.Caption = "View quote letter"
End if
End sub

This works fine. The form has a bound control QuoteNumber with its
control source as QuoteNumber. This is a text field.

However I wish to extend this and disable another button if the
QuoteNumber has a particular value:
Private Sub Form_Current()
If IsNull(me.QuoteNumber) Then
Me.quoteLetterButton.Caption = "Create quote letter"
Else
If Me.QuoteNumber = "Regret" Then
Me.RegretButton.Enabled = false
Else
Me.quoteLetterButton.Caption = "View quote letter"
End if
End if
End sub

As soon as I do this I get:
Run-time error 2424
The expression you entered has a field, control, property name that
Microsoft Access can't find.

So I simplified it to:
Private Sub Form_Current()
Debug.print Me.QuoteNumber
If IsNull(me.QuoteNumber) Then
Me.quoteLetterButton.Caption = "Create quote letter"
Else
Me.quoteLetterButton.Caption = "View quote letter"
End if
End sub
but this gives the same error. In the working version at the top I can
step through with the debugger and see that Me.QuoteNumber has correct
values, either null or some text but as soon as I try to use the value
of the control/field in some other way things go pear shaped.

Why is it that when I try to do anything else with it, I get an error?

I have replaced the . by !, decompiled, compacted and even deleted the
form and imported a fresh copy from another database but to no avail.
I must have done something similar a thousand times without problem but
something odd seems to be happening here.

Any guesses would be welcome.

Jim

Oct 14 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
>I can step through with the debugger and see that Me.QuoteNumber has
>correct values, either null or some text but as soon as I try to use
the value of the control/field in some other way things go pear
shaped.

Why is it that when I try to do anything else with it, I get an
error?
Sometimes things can get confusing to Access when...

1. The developer relies on the default property of an object. In some
contexts Access can get annoyed if you refer to just the object name
(Me.QuoteNumber) when you really mean its default property
(Me.QuoteNumber.Value).

....and/or...

2. A control on the form/report has the same name as a field in the
underlying recordset. Unfortunately, this is the case when you drag a
field from the field list and drop it onto the form/report. Sometimes
just changing the name of the control from "QuoteNumber" to
"txtQuoteNumber" can clear things up.
Jim Devenish wrote:
The current event of a continuous form is:
Private Sub Form_Current()
If IsNull(me.QuoteNumber) Then
Me.quoteLetterButton.Caption = "Create quote letter"
Else
Me.quoteLetterButton.Caption = "View quote letter"
End if
End sub

This works fine. The form has a bound control QuoteNumber with its
control source as QuoteNumber. This is a text field.

However I wish to extend this and disable another button if the
QuoteNumber has a particular value:
Private Sub Form_Current()
If IsNull(me.QuoteNumber) Then
Me.quoteLetterButton.Caption = "Create quote letter"
Else
If Me.QuoteNumber = "Regret" Then
Me.RegretButton.Enabled = false
Else
Me.quoteLetterButton.Caption = "View quote letter"
End if
End if
End sub

As soon as I do this I get:
Run-time error 2424
The expression you entered has a field, control, property name that
Microsoft Access can't find.

So I simplified it to:
Private Sub Form_Current()
Debug.print Me.QuoteNumber
If IsNull(me.QuoteNumber) Then
Me.quoteLetterButton.Caption = "Create quote letter"
Else
Me.quoteLetterButton.Caption = "View quote letter"
End if
End sub
but this gives the same error. In the working version at the top I can
step through with the debugger and see that Me.QuoteNumber has correct
values, either null or some text but as soon as I try to use the value
of the control/field in some other way things go pear shaped.

Why is it that when I try to do anything else with it, I get an error?

I have replaced the . by !, decompiled, compacted and even deleted the
form and imported a fresh copy from another database but to no avail.
I must have done something similar a thousand times without problem but
something odd seems to be happening here.

Any guesses would be welcome.

Jim
Oct 14 '06 #2

P: n/a
Hi Jim

Perhaps a control name is not the same as the field name?

Here's an alternative to try. Using the With construct should prevent if
from barfing half way through, and might help identify where the problem
really lies. Just as importantly, the buttons' Caption/Enabled properties
are set for all cases: that gets really messy to maintain when you have
nested If blocks. As a minor issue, it sets the values only if they need
changing (since setting is much slower than testing.) HTH:

Private Sub Form_Current()
Dim bDisable As Boolean
Dim strCaption As String

With Me.QuoteNumber
If IsNull(.Value) Then
strCaption = "Create quote letter"
Else
strCaption = "View quote letter"
If .Value = "Regret" Then
bDisable = True
End If
End If
End With

With Me.RegretButton
If .Enabled = bDisable Then
.Enabled = Not bDisable
End If
End With

With Me.quoteLetterButton
If .Caption <strCaption Then
.Caption = strCaption
End If
End With
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"Jim Devenish" <in***************@foobox.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
The current event of a continuous form is:
Private Sub Form_Current()
If IsNull(me.QuoteNumber) Then
Me.quoteLetterButton.Caption = "Create quote letter"
Else
Me.quoteLetterButton.Caption = "View quote letter"
End if
End sub

This works fine. The form has a bound control QuoteNumber with its
control source as QuoteNumber. This is a text field.

However I wish to extend this and disable another button if the
QuoteNumber has a particular value:
Private Sub Form_Current()
If IsNull(me.QuoteNumber) Then
Me.quoteLetterButton.Caption = "Create quote letter"
Else
If Me.QuoteNumber = "Regret" Then
Me.RegretButton.Enabled = false
Else
Me.quoteLetterButton.Caption = "View quote letter"
End if
End if
End sub

As soon as I do this I get:
Run-time error 2424
The expression you entered has a field, control, property name that
Microsoft Access can't find.

So I simplified it to:
Private Sub Form_Current()
Debug.print Me.QuoteNumber
If IsNull(me.QuoteNumber) Then
Me.quoteLetterButton.Caption = "Create quote letter"
Else
Me.quoteLetterButton.Caption = "View quote letter"
End if
End sub
but this gives the same error. In the working version at the top I can
step through with the debugger and see that Me.QuoteNumber has correct
values, either null or some text but as soon as I try to use the value
of the control/field in some other way things go pear shaped.

Why is it that when I try to do anything else with it, I get an error?

I have replaced the . by !, decompiled, compacted and even deleted the
form and imported a fresh copy from another database but to no avail.
I must have done something similar a thousand times without problem but
something odd seems to be happening here.

Any guesses would be welcome.

Jim

Oct 14 '06 #3

P: n/a
Thank you both for your help. Sadly nothing worked. So I started this
one again and designed a new form to replace this and got it to do just
what I wanted in much the way I had originally intended.

I guess that the first form got itself in a mess and nothing would sort
it out. I will leave as one of life's little mysteries.

JIM
Allen Browne wrote:
Hi Jim

Perhaps a control name is not the same as the field name?

Here's an alternative to try. Using the With construct should prevent if
from barfing half way through, and might help identify where the problem
really lies. Just as importantly, the buttons' Caption/Enabled properties
are set for all cases: that gets really messy to maintain when you have
nested If blocks. As a minor issue, it sets the values only if they need
changing (since setting is much slower than testing.) HTH:

Private Sub Form_Current()
Dim bDisable As Boolean
Dim strCaption As String

With Me.QuoteNumber
If IsNull(.Value) Then
strCaption = "Create quote letter"
Else
strCaption = "View quote letter"
If .Value = "Regret" Then
bDisable = True
End If
End If
End With

With Me.RegretButton
If .Enabled = bDisable Then
.Enabled = Not bDisable
End If
End With

With Me.quoteLetterButton
If .Caption <strCaption Then
.Caption = strCaption
End If
End With
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"Jim Devenish" <in***************@foobox.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
The current event of a continuous form is:
Private Sub Form_Current()
If IsNull(me.QuoteNumber) Then
Me.quoteLetterButton.Caption = "Create quote letter"
Else
Me.quoteLetterButton.Caption = "View quote letter"
End if
End sub

This works fine. The form has a bound control QuoteNumber with its
control source as QuoteNumber. This is a text field.

However I wish to extend this and disable another button if the
QuoteNumber has a particular value:
Private Sub Form_Current()
If IsNull(me.QuoteNumber) Then
Me.quoteLetterButton.Caption = "Create quote letter"
Else
If Me.QuoteNumber = "Regret" Then
Me.RegretButton.Enabled = false
Else
Me.quoteLetterButton.Caption = "View quote letter"
End if
End if
End sub

As soon as I do this I get:
Run-time error 2424
The expression you entered has a field, control, property name that
Microsoft Access can't find.

So I simplified it to:
Private Sub Form_Current()
Debug.print Me.QuoteNumber
If IsNull(me.QuoteNumber) Then
Me.quoteLetterButton.Caption = "Create quote letter"
Else
Me.quoteLetterButton.Caption = "View quote letter"
End if
End sub
but this gives the same error. In the working version at the top I can
step through with the debugger and see that Me.QuoteNumber has correct
values, either null or some text but as soon as I try to use the value
of the control/field in some other way things go pear shaped.

Why is it that when I try to do anything else with it, I get an error?

I have replaced the . by !, decompiled, compacted and even deleted the
form and imported a fresh copy from another database but to no avail.
I must have done something similar a thousand times without problem but
something odd seems to be happening here.

Any guesses would be welcome.

Jim
Oct 14 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.