From: Afrosheen via AccessMonster.com on 4 Jun 2010 09:50 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. -- Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/201006/1
From: Tom van Stiphout on 4 Jun 2010 10:08 On Fri, 04 Jun 2010 13:50:06 GMT, "Afrosheen via AccessMonster.com" <u46942(a)uwe> wrote: 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. >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.
From: Afrosheen via AccessMonster.com on 4 Jun 2010 10:56 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. Tom van Stiphout wrote: >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. -- Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/201006/1
From: Afrosheen via AccessMonster.com on 4 Jun 2010 16:50 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. Afrosheen wrote: >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] >>> >>>Again, thanks for your help. -- Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/201006/1
|
Pages: 1 Prev: Tracking changes to a form's fields---still searching for an answe Next: 2 list box iteration |