From: Alan on

Hi I was given this code to look up on two combo box name

Customer Number
Posting Date Period

which then a third combo box would look up on these two combo box an sum the
value Amount field in a table

for example

Customer Number C00001
Posting Date 2009/07
Amount £5000

This is my code so far

=DSum("Amount",
" July 09 - On Billings and Adjustments Data Query ",
" Format (Customer No#, "text) = " & Format
(cboCustomerNumber.Value, "text") &
" AND Format(Posting Date Period, "yyyymm) = "'" &
Format(cboPostingDate.Value, "yyyymm") & "'")

i tired changing the format of the customer number because it begins with a
C so must be a text field,

but i keep getting the same old error

Invaild syntax

You may have enetred an operand without and operator

can anyone help

many thanks


From: Douglas J. Steele on
Since July 09 - On Billings and Adjustments Data Query has spaces in it,
you need to put square brackets around it (and presumably there aren't
actually spaces at the beginning and end of the name (same with field names,
btw). Also, I don't think there's a need to format Customer Number.

=DSum("Amount",
"[July 09 - On Billings and Adjustments Data Query]",
" [Customer No#] = " & cboCustomerNumber &
" AND Format([Posting Date Period], "yyyymm) = "'" &
Format(cboPostingDate, "yyyymm") & "'")

If Customer No# is a text field, you'll need

=DSum("Amount",
"[July 09 - On Billings and Adjustments Data Query]",
" [Customer No#] = '" & cboCustomerNumber & "'" &
" AND Format([Posting Date Period], "yyyymm) = "'" &
Format(cboPostingDate, "yyyymm") & "'")

Incidentally, do yourself a HUGE favour, and stop using special characters
(like # and spaces) in your field and table names!

--
Doug Steele, Microsoft Access MVP
http://www.AccessMVP.com/DJSteele
(no e-mails, please!)

"Alan" <Alan(a)discussions.microsoft.com> wrote in message
news:CC199FBC-8EEE-4783-A76C-24000D9C843C(a)microsoft.com...
>
> Hi I was given this code to look up on two combo box name
>
> Customer Number
> Posting Date Period
>
> which then a third combo box would look up on these two combo box an sum
> the
> value Amount field in a table
>
> for example
>
> Customer Number C00001
> Posting Date 2009/07
> Amount �5000
>
> This is my code so far
>
> =DSum("Amount",
> " July 09 - On Billings and Adjustments Data Query ",
> " Format (Customer No#, "text) = " & Format
> (cboCustomerNumber.Value, "text") &
> " AND Format(Posting Date Period, "yyyymm) = "'" &
> Format(cboPostingDate.Value, "yyyymm") & "'")
>
> i tired changing the format of the customer number because it begins with
> a
> C so must be a text field,
>
> but i keep getting the same old error
>
> Invaild syntax
>
> You may have enetred an operand without and operator
>
> can anyone help
>
> many thanks
>
>


From: RonaldoOneNil on
Look out for removing spaces insided double quotes, single quotes around text
values & square brackets on field names with spaces in.

=DSum("Amount","July 09 - On Billings and Adjustments Data
Query","[Customer Number] = '" & cboCustomerNumber & "' AND [Posting Date
Period] = '" & cboPostingDate & "'")


"Alan" wrote:

>
> Hi I was given this code to look up on two combo box name
>
> Customer Number
> Posting Date Period
>
> which then a third combo box would look up on these two combo box an sum the
> value Amount field in a table
>
> for example
>
> Customer Number C00001
> Posting Date 2009/07
> Amount £5000
>
> This is my code so far
>
> =DSum("Amount",
> " July 09 - On Billings and Adjustments Data Query ",
> " Format (Customer No#, "text) = " & Format
> (cboCustomerNumber.Value, "text") &
> " AND Format(Posting Date Period, "yyyymm) = "'" &
> Format(cboPostingDate.Value, "yyyymm") & "'")
>
> i tired changing the format of the customer number because it begins with a
> C so must be a text field,
>
> but i keep getting the same old error
>
> Invaild syntax
>
> You may have enetred an operand without and operator
>
> can anyone help
>
> many thanks
>
>
From: BruceM via AccessMonster.com on
Because quotes tend to confound me, and the quotes didn't look quite right, I
tried an experiment, except I used StartDate in one of my tables. In a text
box double click event on an existing form:

Dim strWhere As String

strWhere = "Format([StartDate], "yyyymm) = "'" & Format(txtStartDate,
"yyyymm") & "'"
Debug.Print strWhere

MsgBox = DCount("*", "tblBatch", strWhere)

I tried adding closing quotes around the first yyyymm, and a lot of other
combinations, until I found:

strWhere = "Format([StartDate], ""yyyymm"") = " & Format(Me.txtStartDate,
"yyyymm")

The second part of the expression behaves as if it is a string variable. In
fact, it worked when I substituted a string variable for the part of the
expression after the ampersand:

Dim str1 as String, strWhere as String

str1 = Format(Me.txtStartDate, "yyyymm")
strWhere = "Format([StartDate], ""yyyymm"") = " & str1

I expect there are about a dozen other ways to do that. Just making an
observation, and expressing some frustration with quote marks.

Douglas J. Steele wrote:
>Since July 09 - On Billings and Adjustments Data Query has spaces in it,
>you need to put square brackets around it (and presumably there aren't
>actually spaces at the beginning and end of the name (same with field names,
>btw). Also, I don't think there's a need to format Customer Number.
>
>=DSum("Amount",
> "[July 09 - On Billings and Adjustments Data Query]",
> " [Customer No#] = " & cboCustomerNumber &
> " AND Format([Posting Date Period], "yyyymm) = "'" &
> Format(cboPostingDate, "yyyymm") & "'")
>
>If Customer No# is a text field, you'll need
>
>=DSum("Amount",
> "[July 09 - On Billings and Adjustments Data Query]",
> " [Customer No#] = '" & cboCustomerNumber & "'" &
> " AND Format([Posting Date Period], "yyyymm) = "'" &
> Format(cboPostingDate, "yyyymm") & "'")
>
>Incidentally, do yourself a HUGE favour, and stop using special characters
>(like # and spaces) in your field and table names!
>
>> Hi I was given this code to look up on two combo box name
>>
>[quoted text clipped - 33 lines]
>>
>> many thanks

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-forms/201003/1

From: Douglas J. Steele on
Oops, that actually needs to be

=DSum("Amount",
"[July 09 - On Billings and Adjustments Data Query]",
" [Customer No#] = " & cboCustomerNumber &
" AND Format([Posting Date Period], ""yyyymm"") = " &
Format(cboPostingDate, "yyyymm"))

or

=DSum("Amount",
"[July 09 - On Billings and Adjustments Data Query]",
" [Customer No#] = " & cboCustomerNumber &
" AND Format([Posting Date Period], ""yyyymm"") = '" &
Format(cboPostingDate, "yyyymm") & "'")


--
Doug Steele, Microsoft Access MVP
http://www.AccessMVP.com/DJSteele
(no e-mails, please!)

"Douglas J. Steele" <NOSPAM_djsteele(a)NOSPAM_gmail.com> wrote in message
news:%23vIzlF0yKHA.928(a)TK2MSFTNGP05.phx.gbl...
> Since July 09 - On Billings and Adjustments Data Query has spaces in it,
> you need to put square brackets around it (and presumably there aren't
> actually spaces at the beginning and end of the name (same with field
> names, btw). Also, I don't think there's a need to format Customer Number.
>
> =DSum("Amount",
> "[July 09 - On Billings and Adjustments Data Query]",
> " [Customer No#] = " & cboCustomerNumber &
> " AND Format([Posting Date Period], "yyyymm) = "'" &
> Format(cboPostingDate, "yyyymm") & "'")
>
> If Customer No# is a text field, you'll need
>
> =DSum("Amount",
> "[July 09 - On Billings and Adjustments Data Query]",
> " [Customer No#] = '" & cboCustomerNumber & "'" &
> " AND Format([Posting Date Period], "yyyymm) = "'" &
> Format(cboPostingDate, "yyyymm") & "'")
>
> Incidentally, do yourself a HUGE favour, and stop using special characters
> (like # and spaces) in your field and table names!
>
> --
> Doug Steele, Microsoft Access MVP
> http://www.AccessMVP.com/DJSteele
> (no e-mails, please!)
>
> "Alan" <Alan(a)discussions.microsoft.com> wrote in message
> news:CC199FBC-8EEE-4783-A76C-24000D9C843C(a)microsoft.com...
>>
>> Hi I was given this code to look up on two combo box name
>>
>> Customer Number
>> Posting Date Period
>>
>> which then a third combo box would look up on these two combo box an sum
>> the
>> value Amount field in a table
>>
>> for example
>>
>> Customer Number C00001
>> Posting Date 2009/07
>> Amount �5000
>>
>> This is my code so far
>>
>> =DSum("Amount",
>> " July 09 - On Billings and Adjustments Data Query ",
>> " Format (Customer No#, "text) = " & Format
>> (cboCustomerNumber.Value, "text") &
>> " AND Format(Posting Date Period, "yyyymm) = "'" &
>> Format(cboPostingDate.Value, "yyyymm") & "'")
>>
>> i tired changing the format of the customer number because it begins with
>> a
>> C so must be a text field,
>>
>> but i keep getting the same old error
>>
>> Invaild syntax
>>
>> You may have enetred an operand without and operator
>>
>> can anyone help
>>
>> many thanks
>>
>>
>
>