# Incorrect Property Value 2nd time through loop [closed]

Hi folks! I'm working on a database that will track the weekly giving of a church and produce a deposit slip for our treasurer. It uses macros to total the various types of money coming in (coins, bills, checks), but I'm having a problem with the macro that totals up the checks.

The database table has 30 columns for checks (labeled Checks_1, Checks_2, Checks_3, etc) and each of these columns has a control on the main form so that the treasurers can enter the checks one by one. The table also has a column called Checks_Total that is to be dynamically updated by a macro that adds up all the checks as they're being entered in.

I've been able to successfully write a macro to accomplish this for the other types of giving (coins/bills), but because of the number of columns, I am attempting to do the same thing through a for...next loop. However, I'm running into an "Incorrect Property Value" error in this. As I've worked on debugging this, I've discovered that the first time through the loop, it works fine. It's on the second time through the loop that I get the error. I'm not much of a programmer, but I'm learning. Here is a snippet of the code for that macro. Hopefully you can find what it is I'm doing wrong:

Dim TotChecks, addToTotal
Dim checksGBN as String

root_form = ThisComponent.Drawpage.Forms
main_frm = root_form.getByName("MainForm")

For Counter = 0 to 29
checksGBN = "fmtChecks_" + (Counter + 1)
TotChecks = TotChecks + addToTotal ' incorrect property value 2nd time
Next Counter


I've tried designating the TotChecks and addToTotal variables as various types (such as Double, Single, and Currency) but it fails the first time through the loop. I've also tried running conversion functions on them (such as CSng, CDbl) but to no avail. Also, running "TypeName" on the variables shows that they become Objects after they are given a value. Not sure if this is the problem and/or how I can overcome this.

Edit: Just in case it would help to see how I managed to do this with the other types of giving, here's the rest of my macros (including all the debugging garbage I had inserted into the above code):

Sub CalculateCoins (oEvent As Object)

Dim DatabaseContext As Object
Dim DataSource As Object
Dim Connection As Object
Dim InteractionHandler as Object
Dim strSQL as String
Dim Conn
Dim Stmt
Dim DB
Dim TableName as String
Dim DatabaseName as String

DatabaseContext = createUnoService("com.sun.star.sdb.DatabaseContext")
DatabaseName = "LBCN_Giving_Database"
DataSource = DatabaseContext.getByName(DatabaseName)
TableName = "Main_Database_Table"

Connection = DataSource.GetConnection("","")

Dim NumDollars, NumQuarters, NumDimes, NumNickels, NumPennies
Dim TotCoins as Double

root_form = ThisComponent.Drawpage.Forms
main_frm = root_form.getByName("MainForm")
NumDollars = main_frm.getByName("fmtCoins_100")
NumQuarters = main_frm.getByName("fmtCoins_25")
NumDimes = main_frm.getByName("fmtCoins_10")
NumNickels = main_frm.getByName("fmtCoins_5")
NumPennies = main_frm.getByName("fmtCoins_1")
TotCoins = (CInt(NumDollars.text) + (CInt(NumQuarters.text) * .25) + (CInt ...
edit retag reopen merge delete

### Closed for the following reason the question is answered, right answer was accepted by Alex Kemp close date 2020-09-14 15:10:53.008500

Sort by » oldest newest most voted

Just looking at the initial routine you have a problem with this line:

TotChecks = TotChecks + addToTotal

Edit: A secondary glance also shows you never initialize total fields. You should always do this. For example, before your loop for check addition - TotChecks = 0.00.

more

Ah, thank-you so much! I was guessing that it was an issue with addToTotal being an Object, but I couldn't figure out how to deal with it. This worked perfectly. Initially, it didn't like "addToTotal.Value" but what worked was doing TotChecks = TotChecks + CDbl(addToTotal.Text).

Thank-you Ratslinger! This LibreOffice community has been fantastic, and has helped me so much to design databases that do exactly what I want them to do. Keep it up, folks!

( 2016-10-28 17:11:24 +0200 )edit

You are very welcome. The .Text or .Value is dependent upon the control/data type being used. My guess was .Text but included both for safety sake.

( 2016-10-28 17:20:11 +0200 )edit