Number Error Problem

  • Thread starter Afrosheen via AccessMonster.com
  • Start date
A

Afrosheen via AccessMonster.com

First of all thanks for reading my post.
I have 4 number fields in my table. The default is set to nothing, not 0.
In my form when I click on numbers 1-3 I have no problem. I did a msgbox on
number 3 and 4. Number 3 field shows nothing and no error. Number 4 field
shows a 0 and gives me a null error

I have all the fields dim as integer

Here is my code for number 4 field:
Private Sub Unit4_GotFocus()
MsgBox u4
10 u4 = Unit4
End Sub

Am I doing something wrong? I have fields set up the same way as above and I
don't have a problem.

What I'm trying to do is to compare u4 with the new information in field 4.
Private Sub Unit4_BeforeUpdate(Cancel As Integer)
20 If Unit4 < u4 Then
30 Tot = Tot - Unit4
40 Else
50 Tot = Tot + Unit4
60 End If
End Sub

Again, thanks for your help.
 
T

Tom van Stiphout

On Fri, 04 Jun 2010 13:50:06 GMT, "Afrosheen via AccessMonster.com"

If u4 is null at the time you run the "Msgbox u4" line, you will get
this error. Set a breakpoint on this line, run the code again, and
inspect the value.

One way this often happens is if "Option Explicit" is not set at the
top of every module. Set this to be the default in Tools > Options as
well.

Another way is if you dim variables incorrectly:
Dim u1, u2, u3, u4 As Integer
Debug.Print VarType(u1), VarType(u2), VarType(u3), VarType(u4)
results in:
0 0 0 2
Look up VarType in the help file.
Resolve to declare one variable per line.

-Tom.
Microsoft Access MVP
 
A

Afrosheen via AccessMonster.com

Thanks for getting back so fast.
This is what I did. When I changed the dim to all one line then ran the debug.
print. The answers I got were all 2.
If u4 is null at the time you run the "Msgbox u4" line, you will get
this error. Set a breakpoint on this line, run the code again, and
inspect the value.

One way this often happens is if "Option Explicit" is not set at the
top of every module. Set this to be the default in Tools > Options as
well.

Another way is if you dim variables incorrectly:
Dim u1, u2, u3, u4 As Integer
Debug.Print VarType(u1), VarType(u2), VarType(u3), VarType(u4)
results in:
0 0 0 2
Look up VarType in the help file.
Resolve to declare one variable per line.

-Tom.
Microsoft Access MVP
First of all thanks for reading my post.
I have 4 number fields in my table. The default is set to nothing, not 0.
[quoted text clipped - 23 lines]
Again, thanks for your help.
 
A

Afrosheen via AccessMonster.com

Hi Tom,
I couldn't get it so I cheated. I put a 5 Dim and then the 4 fields worked.
The 5Dim is just a dummy Dim and don't need it.

It's probably not the right way to do it.

Thanks for the help.

Thanks for getting back so fast.
This is what I did. When I changed the dim to all one line then ran the debug.
print. The answers I got were all 2.
If u4 is null at the time you run the "Msgbox u4" line, you will get
this error. Set a breakpoint on this line, run the code again, and
[quoted text clipped - 20 lines]
 

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