Error using command button navigation

S

silva

I use command button navigation to perform certain tasks as I move from
record to record in a form. Somehow I get an error that only shows up for
unpopulated records (only the primary key has data and there's no associated
data in the subform). The error:

Microsoft Office Access can't find the field '|' referred to in your
expression.

This occurs for all five navigation command buttons (First, Last, Previous,
Next records and Close Form). The code added to each button is as follows:

[Balance] = [record_sum]
If [record_sum] <= 0 Then
[Fee_Box] = 0
ElseIf [Radio_Button_A] = True And [record_sum] <= 400 And [record_sum]
[Fee_Box] = Round(40, 2)
ElseIf [Radio_Button_A] = True And [record_sum] > 400 Then
[Fee_Box] = Round([record_sum] * 0.1, 2)
ElseIf [Radio_Button_B] = True And [record_sum] > 0 Then
[Fee_Box] = Round(40, 2)
End If

The code determines a late fee based on the balance (10%) if radio button A
is selected with a balance greater than $400.00, $40.00 if radio button A is
selected and the balance is between $400.00 and $0.00, $40.00 if radio button
B is selected and the balance is greater than $0.00, or $0.00 if the balance
is $0.00 or there is a credit on the balance.

The remaining code attached to each button is default code inserted by
Access relevant to the button. I think the problem may be related to the
[record_sum] field being empty, but I'm not sure.

Any clue as to why it gives an error with an unpopulated record would be
appreciated.
 
J

Jeanette Cunningham

You can tell access to run that code only when there are records in the
subform.
Here is one way to do this.
On the subform (I assume this is where the code below is situated) change
the code to tell access not to run that code if the subform is at a new
record.


If Me.NewRecord Then
'handle error here
Else
[Balance] = [record_sum]
If [record_sum] <= 0 Then
[Fee_Box] = 0
ElseIf [Radio_Button_A] = True And [record_sum] <= 400 And [record_sum]
[Fee_Box] = Round(40, 2)
ElseIf [Radio_Button_A] = True And [record_sum] > 400 Then
[Fee_Box] = Round([record_sum] * 0.1, 2)
ElseIf [Radio_Button_B] = True And [record_sum] > 0 Then
[Fee_Box] = Round(40, 2)
End If
End If

Jeanette Cunningham


silva said:
I use command button navigation to perform certain tasks as I move from
record to record in a form. Somehow I get an error that only shows up for
unpopulated records (only the primary key has data and there's no
associated
data in the subform). The error:

Microsoft Office Access can't find the field '|' referred to in your
expression.

This occurs for all five navigation command buttons (First, Last,
Previous,
Next records and Close Form). The code added to each button is as follows:

[Balance] = [record_sum]
If [record_sum] <= 0 Then
[Fee_Box] = 0
ElseIf [Radio_Button_A] = True And [record_sum] <= 400 And [record_sum]
[Fee_Box] = Round(40, 2)
ElseIf [Radio_Button_A] = True And [record_sum] > 400 Then
[Fee_Box] = Round([record_sum] * 0.1, 2)
ElseIf [Radio_Button_B] = True And [record_sum] > 0 Then
[Fee_Box] = Round(40, 2)
End If

The code determines a late fee based on the balance (10%) if radio button
A
is selected with a balance greater than $400.00, $40.00 if radio button A
is
selected and the balance is between $400.00 and $0.00, $40.00 if radio
button
B is selected and the balance is greater than $0.00, or $0.00 if the
balance
is $0.00 or there is a credit on the balance.

The remaining code attached to each button is default code inserted by
Access relevant to the button. I think the problem may be related to the
[record_sum] field being empty, but I'm not sure.

Any clue as to why it gives an error with an unpopulated record would be
appreciated.
 
S

silva

Thanks for the help, but it appears that it was completely unnecessary. I was
dumb enough to enter the wrong name for a field and it screwed the whole
thing up. A minor mistype copy-and-pasted multiple times made a big mess. The
scripting now runs as it should. Thank you for taking the time, though. It is
still appreciated.


Jeanette Cunningham said:
You can tell access to run that code only when there are records in the
subform.
Here is one way to do this.
On the subform (I assume this is where the code below is situated) change
the code to tell access not to run that code if the subform is at a new
record.


If Me.NewRecord Then
'handle error here
Else
[Balance] = [record_sum]
If [record_sum] <= 0 Then
[Fee_Box] = 0
ElseIf [Radio_Button_A] = True And [record_sum] <= 400 And [record_sum]
[Fee_Box] = Round(40, 2)
ElseIf [Radio_Button_A] = True And [record_sum] > 400 Then
[Fee_Box] = Round([record_sum] * 0.1, 2)
ElseIf [Radio_Button_B] = True And [record_sum] > 0 Then
[Fee_Box] = Round(40, 2)
End If
End If

Jeanette Cunningham


silva said:
I use command button navigation to perform certain tasks as I move from
record to record in a form. Somehow I get an error that only shows up for
unpopulated records (only the primary key has data and there's no
associated
data in the subform). The error:

Microsoft Office Access can't find the field '|' referred to in your
expression.

This occurs for all five navigation command buttons (First, Last,
Previous,
Next records and Close Form). The code added to each button is as follows:

[Balance] = [record_sum]
If [record_sum] <= 0 Then
[Fee_Box] = 0
ElseIf [Radio_Button_A] = True And [record_sum] <= 400 And [record_sum]
[Fee_Box] = Round(40, 2)
ElseIf [Radio_Button_A] = True And [record_sum] > 400 Then
[Fee_Box] = Round([record_sum] * 0.1, 2)
ElseIf [Radio_Button_B] = True And [record_sum] > 0 Then
[Fee_Box] = Round(40, 2)
End If

The code determines a late fee based on the balance (10%) if radio button
A
is selected with a balance greater than $400.00, $40.00 if radio button A
is
selected and the balance is between $400.00 and $0.00, $40.00 if radio
button
B is selected and the balance is greater than $0.00, or $0.00 if the
balance
is $0.00 or there is a credit on the balance.

The remaining code attached to each button is default code inserted by
Access relevant to the button. I think the problem may be related to the
[record_sum] field being empty, but I'm not sure.

Any clue as to why it gives an error with an unpopulated record would be
appreciated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top