Home

Macros and Programming

 

CardboxForumsMacros and Programming > "Totalling fields when editing a record (some fields are empty)"

Totalling fields when editing a record (some fields are empty)

Current user: [none]
Register / Log In · Help

Posted By Post

DLROI

22-Feb-2007 16:43

I am editing a record. I have made a macro totalling some 20 different fields in the current record. I put the total in another field of the record. It works fine if all fields do contain something but NOT if field(s)are empty. Can somebody help me? Thank you.

Mary Doyle

22-Feb-2007 20:00

Try something like the following

x = 0

a = Fields("F1")
If a <> "" Then ' i.e. if F1 field is not empty
x = 0 + x + a
End If
b = Fields("F2")
If b <> "" Then
x = 0 + x + b ' At this point x = a+b (if F1 wasn't empty)
End If
c = Fields("F3")
If c <> "" Then
x = 0 + x + c
End If
d = Fields("F4")
If d <> "" Then
x = 0 + x + d
End If

Fields("total") = x

May be a neater way of doing it but the above works.

Mary

Quick Reply

Please log in or register before trying to post a reply.

 
© 2010 Cardbox Software Limited   Home