Ron said:
I am back again. . . So soon.
Last night I added two more to the case statement and ran it. It worked fine.
Tonight I added three more to the case statement. Just so you will know I
did nothing else to the code, here is the whole thing. In the future I will
remove the additional case parts.
Function TotalFinder(Name As String)
Dim dbs As Database, rst As DAO.Recordset
Dim Column As String
Dim TaxesCol As String
Dim Income As Currency
Dim Taxes As Currency
Income = 0
That's a statement!
Mine isn't 0
)
Taxes = 0
Select Case Name
Case Is = "Chores"
If you do a straight compare (to one value), you don't need "Case Is",
the plain 'Case "Chores"' should do.
I'd take this out of the Case structure because you need it in every
Case (funny). Saves a lot of lines.
Set rst = dbs.OpenRecordset("Chores")
Column = "ChoresIN"
Case Is = "Data Processing"
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("Data Processing")
Column = "DPIN"
Case Is = "Coffee Sales"
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("Coffee Sales")
Column = "CoffeeIN"
Case Is = "Materials"
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("Materials")
Column = "IN"
Case Is = "Supplies"
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("Supplies")
Column = "Out"
Case Is = "Equipment"
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("Equipment")
Column = "Cost"
End Select
Do
Income = Income + rst(Column) [1]
rst.MoveNext
Loop Until rst.EOF
TotalFinder = Income
'Debug.Print Income, Taxes
End Function
Now I am getting runtime error 91 Object variable or With block variable
not set
?????
I don't understand how this came about overnight
hmm, you don't say how this was run, but I suspect you supplied a Name
that is not in any Case. Hence, no dbs was set (you will overcome this
with my suggestion of taking the Set out of the Case) and no rst was set.
If you do just want to sum all (fields of) records of a given table, you
could do this in another fashion as well, using the database functionality.
Case "Chores"
TotalFinder = DSum("ChoresIn","Chores")
etc
As far as I can tell there is a problem with your data structure, since
the column you want to sum (obviously of the same data position in the
structure) sits in several tables under different names. Could you
envision all data of this type sitting in one table, possibly with an
extra field indicating its function, so you could just add up the, say,
Income column?
Assuming this table was created as
IncomeTypes(type,income,more-fields-you-have-now), the single statement
for TotalFinder now becomes
TotalFinder=DSum("Income","IncomeTypes","type='"& Name &"'")
--
Bas Cost Budde, Holland
http://www.heuveltop.nl/BasCB/msac_index.html
I prefer human mail above automated so in my address
replace the queue with a tea