Dsum I have almost craked it BUT

S

smason

Hello please have a look at the code below

=DSum("[amount]","[tblamountcon]","[jobid] = '" & [Me].[JobID] & "'")
------------------------------------------

the bit underlined works but i need to reference to the jobID for the filter
but the bit not underlined doesnt work and was sent to kill me!!!!!! jobid is
a text field in both the table and form i get a message in the text box
#Name?

please help o great forum!
 
A

Allen Browne

Omit the Me:
=DSum("[amount]","[tblamountcon]","[jobid] = """ & [JobID] & """")


Me works only in the module of the form/report.
 
D

Douglas J. Steele

Please do not repost questions that you've already asked. I just posted a
response to one of your other threads indicated what the problem was with
what you've got below.
 
A

Allan Murphy

You can do the following

Dim temp_id as string

temp_id = " ' " & Me!JobID& " ' "

=DSum("[amount]","[tblamountcon]","[jobid] = " & temp_id")

OR
=DSum("[amount]","[tblamountcon]","[jobid] = forms!form name!JobID")
where form name is the name of your form.

Allan
 
M

Maarkr

Isn't jobid a number field?
=DSum("[amount]","[tblamountcon]","jobid = " & [JobID])
 
B

BruceM

You have combined two approaches. Also, if JobID is a number it should be
declared as such. If it is a string there is no need for the quotes.

Dim Temp_ID as Long
Temp_ID = Me.JobID

or
Dim Temp_ID as String
Temp_ID = Me.JobID

In VBA you need to assign the DSum result to a field or variable. Here
txtSum is an unbound text box:

Me.txtSum = DSum("[amount]","[tblamountcon]","[jobid] = " & temp_id)

Note that there is no closing quote for the Where condition of DSum.

I suppose if TempID is a string you could add the quotes to the string as
you have done, but you still need either to concatenate another quote or add
another closing quote to the string. I would have to experiment to figure
out just how to work that, if it is possible. It is simpler, I think, to
add the quotes to DSum:

Me.txtSum = DSum("[amount]","[tblamountcon]","[jobid] = """ & temp_id &
"""")
or
Me.txtSum = DSum("[amount]","[tblamountcon]","[jobid] = '" & temp_id & "'")

Allan Murphy said:
You can do the following

Dim temp_id as string

temp_id = " ' " & Me!JobID& " ' "

=DSum("[amount]","[tblamountcon]","[jobid] = " & temp_id")

OR
=DSum("[amount]","[tblamountcon]","[jobid] = forms!form name!JobID")
where form name is the name of your form.

Allan


smason said:
Hello please have a look at the code below

=DSum("[amount]","[tblamountcon]","[jobid] = '" & [Me].[JobID] & "'")
------------------------------------------

the bit underlined works but i need to reference to the jobID for the
filter
but the bit not underlined doesnt work and was sent to kill me!!!!!!
jobid is
a text field in both the table and form i get a message in the text box
#Name?

please help o great forum!
 
B

BruceM

In the first posting the OP stated:
"jobid is a text field"

Maarkr said:
Isn't jobid a number field?
=DSum("[amount]","[tblamountcon]","jobid = " & [JobID])

smason said:
Hello please have a look at the code below

=DSum("[amount]","[tblamountcon]","[jobid] = '" & [Me].[JobID] & "'")
------------------------------------------

the bit underlined works but i need to reference to the jobID for the
filter
but the bit not underlined doesnt work and was sent to kill me!!!!!!
jobid is
a text field in both the table and form i get a message in the text box
#Name?

please help o great forum!
 
S

smason

Thats great thanks

Allen Browne said:
Omit the Me:
=DSum("[amount]","[tblamountcon]","[jobid] = """ & [JobID] & """")


Me works only in the module of the form/report.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

smason said:
Hello please have a look at the code below

=DSum("[amount]","[tblamountcon]","[jobid] = '" & [Me].[JobID] & "'")
------------------------------------------

the bit underlined works but i need to reference to the jobID for the
filter
but the bit not underlined doesnt work and was sent to kill me!!!!!! jobid
is
a text field in both the table and form i get a message in the text box
#Name?

please help o great forum!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top