Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Errors with DSum(fieldname,tablename) - should be simple right??

Status
Not open for further replies.

GolferJohn

Technical User
Aug 22, 2002
26
CA
This should be a very simple problem, yet it eludes this simple newbie.

I have in my main table a numeric field 'ratio' and an unbound textbox 'Text111' on my form.
I entered the following code:

Private Sub Form_Current()
Text111 = (ratio)
End Sub

and lo and behold! the same value in the field 'ratio' on my form appeared in 'text111' So the textbox will accept numbers.
If I insert the code: (where rollbacks is the name of the underlying table)

Private Sub Form_Current()
Text111 = DSum(ratio, rollbacks)
End Sub

I get a compile error 'Expected variable or proceedure, not project'
My database (project?) is called 'Stocks', however my form is also called 'rollbacks' (is this a problem?)

From the msdn library I read:

DSum(expr, domain[, criteria])

expr - An expression that identifies the numeric field whose values you want to total. It can be a string expression identifying a field in a table or query, or . . . . .
domain - A string expression identifying the set of records that constitutes the domain. It can be a table name or a query name.

Private Sub Form_Current()
Me!Text111 = DSum(ratio, rollbacks)
End Sub

yields the same result.

Private Sub Form_Current()
Text111 = Sum(ratio)
End Sub

gives me the error Sub function not defined.

I cannot for the life of me see what I am doing wrong!

Any help would be much apprreciated
Thanks, John
 
Hi John,

A string must be enclosed in quotes; if not it is trated as a variable. Try

Code:
Text111 = DSum("ratio", "rollbacks")

Enjoy,
Tony
 
Hi - OK I played around and I found that I need to enclose the arguments in brackets as:
Text111 = DSum("[ratio]", "[rollbacks]")

Sorry to bother all you busy people.

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top