Home

Macros and Programming

 

CardboxForumsMacros and Programming > "Macro for adding field totals in one record only"

Macro for adding field totals in one record only

Thanks to Bert and Charles for all their help last week. I am now trying to write a macro with the same result but for one record only.

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

Posted By Post

Helen

30-Mar-2009 10:08

Here is the macro that totals fields for a whole selection:

GoToRecord 1
For pos=1 to RecordCount
Set arec = Records (pos)
arec.edit
arec.Fields ("TOTCF") = 0+arec.Fields("CF1")+arec.Fields("CF2")+arec.Fields("CF3")+arec.Fields("CF4")+arec.Fields("CF5")+arec.Fields("CF6")+arec.Fields("CF7")
arec.Fields ("TOTCFA") = 0+arec.Fields("CF1A")+arec.Fields("CF2A")+arec.Fields("CF3A")+arec.Fields("CF4A")+arec.Fields("CF5A")+arec.Fields("CF6A")+arec.Fields("CF7A")
arec.Fields ("TOTCFB") = 0+arec.Fields("CF1B")+arec.Fields("CF2B")+arec.Fields("CF3B")+arec.Fields("CF4B")+arec.Fields("CF5B")+arec.Fields("CF6B")+arec.Fields("CF7B")
arec.Fields ("TOTCFC") = 0+arec.Fields("CF1C")+arec.Fields("CF2C")+arec.Fields("CF3C")+arec.Fields("CF4C")+arec.Fields("CF5C")+arec.Fields("CF6C")+arec.Fields("CF7C")
arec.Fields ("TOTCFD") = 0+arec.Fields("TOTCF")+arec.Fields("TOTCFA")+arec.Fields("TOTCFB")+arec.Fields("TOTCFC")
arec.save
NextRecord
Next

However, despite much trial and error, I don't know how to amend it to make the changes in one record only, and would be very grateful for any help with this.

Many thanks,

Helen

bert

30-Mar-2009 12:00

Hi,
I remarked the lines you do not need when you want to use this only for the current record.
If the record is in edit-mode, it first saves your record (first line).

if ActiveRecord.userediting = true then saverecord
REM GoToRecord 1
REM For pos=1 to RecordCount
Set arec = Records (pos)
arec.edit
arec.Fields ("TOTCF") = 0+arec.Fields("CF1")+arec.Fields("CF2")+arec.Fields("CF3")+arec.Fields("CF4")+arec.Fields("CF5")+arec.Fields("CF6")+arec.Fields("CF7")
arec.Fields ("TOTCFA") = 0+arec.Fields("CF1A")+arec.Fields("CF2A")+arec.Fields("CF3A")+arec.Fields("CF4A")+arec.Fields("CF5A")+arec.Fields("CF6A")+arec.Fields("CF7A")
arec.Fields ("TOTCFB") = 0+arec.Fields("CF1B")+arec.Fields("CF2B")+arec.Fields("CF3B")+arec.Fields("CF4B")+arec.Fields("CF5B")+arec.Fields("CF6B")+arec.Fields("CF7B")
arec.Fields ("TOTCFC") = 0+arec.Fields("CF1C")+arec.Fields("CF2C")+arec.Fields("CF3C")+arec.Fields("CF4C")+arec.Fields("CF5C")+arec.Fields("CF6C")+arec.Fields("CF7C")
arec.Fields ("TOTCFD") = 0+arec.Fields("TOTCF")+arec.Fields("TOTCFA")+arec.Fields("TOTCFB")+arec.Fields("TOTCFC")
arec.save
REM NextRecord
REM Next

I you want a little more develop macros I can advice you to buy the VBScript book that is recommended in the help of Cardbox (VBScript in a nutshell).

regards
bert

Helen

20-Apr-2009 12:37

Thanks Bert!

Quick Reply

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

 
© 2010 Cardbox Software Limited   Home