Results 1 to 6 of 6

Thread: Dsum error

  1. #1
    Join Date
    Jun 2013
    Posts
    16

    Unanswered: Dsum error

    I have use the Dsum function for my query but it gives the error.i have attached the image plz check it and correct my expression.

    The expression is

    Expr1: DSum("Amount","Table1","emID = " & [emID])


    Amount : the Field which i want to calculate

    Table1 : The Table Name

    emID : The Employee ID
    Last edited by ionline; 06-23-13 at 08:56.

  2. #2
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Assuming that the names are correct, if that doesn't work, my guess would be that emID is defined as a Text Datatype, and your syntax is only correct if it were defined as a Number.

    If emID is, in fact, defined is Text, the syntax would be

    Code:
    DSum("Amount","Table1","emID = '" & [emID] & "'")

    Be sure to note that there are some Single Quotes amongst the Double Quotes:

    "emID = '" & [emID] & "'"

    Linq ;0)>
    Last edited by Missinglinq; 06-23-13 at 10:50.
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  3. #3
    Join Date
    Jun 2013
    Posts
    16
    Thanks your are right.I have correct my code and now it is working.Thanks again you really experienced and nice person.Due to your i support i have complete my project .

    Also please if you give me both the Dlookup code for number and text just like above,i will be very thankful to you.

  4. #4
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    All WHERE Clauses use the same basic syntax, whether you're using DSum(), DLookUp(), DCount(), whatever.

    For Numbers:

    DLookup("FieldName", "TableOrQueryName", "NumberField = " & Me.NumberField)

    For Strings/Text: (note the Single Quotes in red)

    DLookup("FieldName", "TableOrQueryName", "TextField = '" & Me.TextField & "'")

    For Dates:

    DLookup("FieldName", "TableOrQueryName", "DateField = #" & Me.DateField & "#")

    Linq ;0)>
    Last edited by Missinglinq; 06-26-13 at 10:03.
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  5. #5
    Join Date
    Jun 2013
    Posts
    16

    Two More Question

    First of all i would like to thank you for your nice support.

    In the previous reply you give me the general syntax for the function Dsum and Dlookup.but one thing is not clear that why you use the world "Me" in the syntax of Dlookup.

    When i use the Dlookup with out using "Me",it is successful.Please explain in Detail that why you use it . Thanks

  6. #6
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    In Access VBA code, Me. can be used instead of using the full reference to the Form a Control resides on. In my code examples, for instance

    "TextField = '" & Me.TextField & "'"

    means 'where the data in the Control named TextField, on the current Form, is the same as the data in field named TextField, in the named Table or Query.

    Note I said 'in VBA code'! If you were using DLookUp elsewhere, such as in a Control Source, you would not use Me., but simply refer to the Control by placing Square Brackets around it, like [TextField].

    It all depends on where you're using the code.

    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •