Jump to content
Compatible Support Forums
Sign in to follow this  
bytemangler

Access 2000

Recommended Posts

Hello all,

Well, I have a project I need to do in Access2000 (why access 2000 and not 2003? corporate have not upg yet). I will be heading to Barnes and Noble later today but here's what I have. I just created a form with rows setup. RowA,B,C, and Total. User will enter numeric data in A,B,C. What I like to to do is on LostFocus (when a user tab away from either a,B, or C) the Total row will automatically sum up the current total. If this require VB script can you give sample please...thanks

 

Share this post


Link to post

I would simply do this:

 

Set each txt box to be numeric only through the properties. Then do the following code where text0/1/2 are the boxes that accept user input and text3 is the total box.

 

Option Compare Database

Option Explicit

 

Private Sub Text0_afterupdate()

Me.Text3 = Me.Text0 + Me.Text1 + Me.Text2

End Sub

 

Private Sub Text1_afterupdate()

Me.Text3 = Me.Text0 + Me.Text1 + Me.Text2

End Sub

 

Private Sub Text2_afterupdate()

Me.Text3 = Me.Text0 + Me.Text1 + Me.Text2

End Sub

 

This way, not matter which field has a value or no value it will add it up.

You can then add error trapping "IF" statements and msgbox's to alert the user to their stupidity. If you've set the boxes to numeric only, they will only accept numbers. It depends on what range of numbers you are expecting. With no error trapping, the boxes will accept any number, small or large.

Share this post


Link to post

Originally posted by Alec§taar:

Quote:
NOTE - FELIX!!! "Shame on you man" - you didn't check to see if the field was blank/null!!!

As far as I'm aware, if the field type is set to "number", the field values default to 0 not to NULL, so you shouldn't need check for NULL fields.

 

Rgds

AndyF

Share this post


Link to post

AndyFair,

You are correct in so much as that when a new record in a table is created the values in a numeric field are set to "0" however on a form where the text field is unbound, the fields will remain NULL unless a value is entered by the user or the default value is set in the field properties.

 

If the field is bound to a field in the table, obviously it will display the value from the table, which unless changed, defaults to "0".

 

F

 

Share this post


Link to post

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×