Results 1 to 10 of 10
  1. #1
    Budatlitho is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Mar 2016
    Posts
    44

    DSum field type "Currency", Data type mismatch


    The "Order amount" field Data Type is defined in 'rs' as "Currency"
    The "amountdue" field Data Type is defined in 'rs1' as "Currency"
    Code fails at the last line, resulting with "Data Type mismatch"
    I've tried
    Code:
     amountdue = Format(DSum("[Order amount]", "Jumbula", _
                "[Participant Member ID (Seven digits)] =""" & eid & """"), "Currency"
    in addition to
    Code:
    amountdue = DSum("[Order amount]", "Jumbula", _
                "[Participant Member ID (Seven digits)] =""" & eid & """")
    Code:
    DoCmd.SetWarnings False
    Dim db As Database
    Dim rs As Recordset
    Dim rs1 As Recordset
    Dim rs2 As Recordset
    Dim strSql As String
    Dim firstname As String
    Dim lastname As String
    Dim name As String
    Dim amountdue As Currency
    Dim amountpaid As Currency
    Dim registrationfee As Currency
    Dim creditcardfee As Currency
    Dim discount As Currency
    Dim balance As Currency
    Dim eid As String
    Dim count As Integer
    Set db = CurrentDb
    db.Execute "DELETE * FROM Symposium_member"
    'strSql = "DROP TABLE [JumbulaTemp];"
    'DoCmd.RunSQL (strSql)
    db.Execute "CREATE TABLE JumbulaTempMember " & _
    "(eid VARCHAR, firstname VARCHAR, lastname VARCHAR, name VARCHAR, amountdue CURRENCY, amountpaid CURRENCY, registrationfee CURRENCY, creditcardfee CURRENCY, discount CURRENCY, balance CURRENCY);"
    RefreshDatabaseWindow
    Set rs = db.OpenRecordset("Jumbula")
    Set rs1 = db.OpenRecordset("JumbulaTempMember")
    rs.MoveFirst
    count = 0
    Do While Not rs.EOF
        If rs.EOF Then Exit Do
        count = count + 1
        eid = rs("[Participant Member ID (Seven digits)]")
        Debug.Print "eid = " & eid;
        firstname = rs("[Participant First name]")
        lastname = rs("[Participant Last name]")
        name = firstname & " " & lastname
        Debug.Print "name = " & name
        Debug.Print "Order amount= " & rs("Order amount")
        amountdue = DSum("[Order amount]", "Jumbula", _
                "[Participant Member ID (Seven digits)] =""" & eid & """")
    What am I missing?

    THANKS in advance!

  2. #2
    jojowhite's Avatar
    jojowhite is offline Competent Performer
    Windows 11 Access 2021
    Join Date
    Jan 2025
    Posts
    430
    when you use Format() function, the result will be a String, not Number.
    so you do not need to use Format() on Dsum().

    also you declared the variable amountDue as Currency (Number).

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    [Participant Member ID (Seven digits)] is a text field?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2021
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,740
    June7, I wondered about that too.
    OP did not include what the result was used for, but the logic seems strange.

    Read sequentially through table Jumbula. For each record, add up the [order amount] in all records in the same table that match the ID of the current record. Advance and do same. How can the results be useful? The amountdue will be equal for all records with same ID.

  5. #5
    Budatlitho is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Mar 2016
    Posts
    44
    I tried with and without Format()
    Cannot variable amountdue be declared as Currency?

  6. #6
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2021
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,740
    Quote Originally Posted by Budatlitho View Post
    I tried with and without Format()
    Cannot variable amountdue be declared as Currency?
    Well, try more stuff. These ideas are to diagnose the problem, not directly fix it.

    Change it to double and see what happens.
    Try the DSum without the criteria to see if that's the problem.
    Change DSum to DCount to check if your syntax is correct.

    Gotta keep on truckin' to get anywhere.
    Last edited by davegri; 03-12-2025 at 04:13 PM. Reason: clarif

  7. #7
    Budatlitho is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Mar 2016
    Posts
    44

    Field types all report the same?

    ... still exploring field types...
    Code:
        Debug.Print "Table name is: " & MyTableDef.name;
        Debug.Print
        For i = 0 To MyTableDef.Fields.count - 1           ' Step through fields in current table
            ' Update Table Definitions table
            TableDefinitions.AddNew      ' Create new record
            TableDefinitions![Table Name] = MyTableDef.name
            TableDefinitions![Field Name] = MyTableDef.Fields(i).name
            TableDefinitions![Data Type] = TypeName(MyTableDef.Fields(i).Type) 'example was wrong
            TableDefinitions![Field Size] = MyTableDef.Fields(i).Size
            TableDefinitions![Field Description] = MyTableDef.Fields(i).Properties("Description")
         'Add to immediate window
            Debug.Print "Field Name is: " & MyTableDef.Fields(i).name _
            & " Data type is: " & TypeName(MyTableDef.Fields(i).Type) _
            & " Field size is: " & MyTableDef.Fields(i).Size
    Immediate window shows:

    Table name is: Jumbula
    Field Name is: Program Data type is: Integer Field size is: 255
    Field Name is: Schedule start/end date Data type is: Integer Field size is: 255
    Field Name is: Tuition name Data type is: Integer Field size is: 255
    Field Name is: Balance Data type is: Integer Field size is: 8


    Table Design shows
    Click image for larger version. 

Name:	JumbulaScreenShot.jpg 
Views:	14 
Size:	62.5 KB 
ID:	52842

    All fields show Integer, not what was selected in Table Design.

    I'm trying to find out why they are different.

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Try declaring the amountdue variable as a Variant. I'd also point out that neither = "[Order amount]" nor "[Participant Member ID (Seven digits)]" are shown in the table you showed above.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    The TypeName() function is not returning correct type name because this is not valid use. This function returns the type for a VBA declared variable. You are using it on constants returned by the Type property, which are all integer numbers. Remove the function and output the numbers. I am not finding any property or function for translating the number values to a string name. Will probably have to build your own table and do a lookup or JOIN in query. https://learn.microsoft.com/en-us/of...e-property-dao
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #10
    Budatlitho is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Mar 2016
    Posts
    44
    THANKS for the explanation! Now I can compare field types from a db from different years tables.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 08-27-2021, 01:50 PM
  2. Replies: 5
    Last Post: 05-11-2021, 09:34 AM
  3. Replies: 8
    Last Post: 04-21-2021, 09:44 AM
  4. Replies: 2
    Last Post: 03-23-2011, 11:43 AM
  5. aSTR = Dir("C:\*.*") >> "Type Mismatch"
    By JGrant in forum Programming
    Replies: 1
    Last Post: 03-28-2009, 05:17 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums