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

    Unable to use number in criteria; string, however, works.

    Hello again!

    I'm still fighting with this function, months later...
    When the variable eid is a string the function will run. If eid is a number, it fails (Run-time error "3464": Data type mismatch in criteria expression"
    I need eid to remain a number.
    If I change these two lines to string it runs. The Jumbula.Participant Member ID (Seven digits) field Data Type is Number

    Dim eid As String
    "(eid VARCHAR, firstname VARCHAR, lastname VARCHAR, name VARCHAR, amountdue CURRENCY, amountpaid CURRENCY, registrationfee CURRENCY, creditcardfee CURRENCY, discount CURRENCY, balance CURRENCY);"



    Code:
    Public Function memberJumbula()
    RefreshDatabaseWindow
    DoCmd.SetWarnings False
    Dim db As Database
    Dim rs As Recordset
    Dim rs1 As Recordset
    Dim rs2 As Recordset
    Dim strSql As String
    Dim eid As Long
    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 count As Integer
    Set db = CurrentDb
    db.Execute "DELETE * FROM Symposium_member"
    db.Execute "CREATE TABLE JumbulaTemp " & _
    "(eid NUMBER, 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("JumbulaTemp")
    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 "Order amount= " & rs("Order amount")
        amountdue = DSum("[Order amount]", "Jumbula", _
                "[Participant Member ID (Seven digits)] =""" & eid & """")
    'fails at this line
        amountpaid = DSum("[Paid amount]", "Jumbula", _
                "[Participant Member ID (Seven digits)] =""" & eid & """")
        registrationfee = Nz(DSum("Registration Fee", "Jumbula", _
                "[Participant Member ID (Seven digits)] =""" & eid & """"))
        creditcardfee = Nz(DSum("Credit Card Convenience Fee", "Jumbula", _
                "[Participant Member ID (Seven digits)] =""" & eid & """"))
        discount = DSum("[Total discount]", "Jumbula", _
                "[Participant Member ID (Seven digits)] =""" & eid & """")
        balance = DSum("Balance", "Jumbula", _
                "[Participant Member ID (Seven digits)] =""" & eid & """")
        Debug.Print "count =" & count & " eid = " & eid & ", " & amountdue & ", " & amountpaid & ", " & registrationfee & ", " & creditcardfee & ", " & discount & ", " & balance; ""
            DoCmd.RunSQL "INSERT INTO JumbulaTemp" & _
            "(eid, firstname, lastname, name, amountdue, amountpaid, registrationfee, creditcardfee, discount, balance)" & _
            "VALUES ('" & eid & "','" & firstname & "','" & lastname & "','" & name & "','" & amountdue & "','" & amountpaid & "','" & registrationfee & "','" & creditcardfee & "','" & discount & "','" & balance & "')"
        rs.MoveNext
    Loop
    'copy to Symposium_member
    rs1.MoveFirst
    Do While Not rs1.EOF
        If rs1.EOF Then Exit Do
        eid = rs1("[eid]")
        firstname = rs1("[firstname]")
        lastname = rs1("[lastname]")
        name = rs1("[name]")
        amountdue = rs1("[amountdue]")
        amountpaid = rs1("[amountpaid]")
        registrationfee = rs1("[registrationfee]")
        creditcardfee = rs1("[creditcardfee]")
        discount = rs1("[discount]")
        balance = rs1("[balance]")
        'unit = rs2("[Unit_Number]")
            DoCmd.RunSQL "INSERT INTO Symposium_member" & _
            "(eid, firstname, lastname, name, amountdue, amountpaid, registrationfee, creditcardfee, discount, balance)" & _
            "VALUES ('" & eid & "','" & firstname & "','" & lastname & "','" & name & "','" & amountdue & "','" & amountpaid & "','" & registrationfee & "','" & creditcardfee & "','" & discount & "','" & balance & "')"
        rs1.MoveNext
    Loop
    rs.Close
    rs1.Close
    strSql = "DROP TABLE [JumbulaTemp];"
    DoCmd.RunSQL (strSql)
    RefreshDatabaseWindow
    DoCmd.SetWarnings True
    End Function

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Either eid is a number type or a string type.
    If number, no surrounding characters required.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    If eid is a number it must be specified in the DSum as

    amountdue = DSum("[Order amount]", "Jumbula", _
    "[Participant Member ID (Seven digits)] =" & eid )

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

    Needs no quotes

    Quote Originally Posted by davegri View Post
    If eid is a number it must be specified in the DSum as

    amountdue = DSum("[Order amount]", "Jumbula", _
    "[Participant Member ID (Seven digits)] =" & eid )
    I see that now. I know I need help with where quotes are required. Does anywhere come to mind where I might find a tutorial/reference?

    THANKS!

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Accidental duplication of post.
    Last edited by June7; 02-24-2024 at 11:36 AM.
    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.

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Here: https://learn.microsoft.com/en-us/of...ng-expressions

    Use # character for date/time parameters.
    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.

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

    Smile Thanks!

    Quote Originally Posted by June7 View Post
    Here: https://learn.microsoft.com/en-us/of...ng-expressions

    Use # character for date/time parameters.
    Great resource. Thank you.

  8. #8
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    "The Jumbula.Participant Member ID (Seven digits) field Data Type is Number"

    It should be noted that 'numbers,' such as IDs (or SSNs, etc) probably should be defined as Strings, with only those used for math, measurements, etc, being defined as Numbers.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

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

    Data type-number

    Quote Originally Posted by Missinglinq View Post
    "The Jumbula.Participant Member ID (Seven digits) field Data Type is Number"

    It should be noted that 'numbers,' such as IDs (or SSNs, etc) probably should be defined as Strings, with only those used for math, measurements, etc, being defined as Numbers.

    Linq ;0)>
    Yes, I understand that string is probably better, but a lot of references in the database need number. Also, it prevents users from entering straight text.

    Have a great day!

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

Similar Threads

  1. Unable to use Date()-1 as Criteria
    By UPSDuder in forum Queries
    Replies: 14
    Last Post: 02-11-2019, 12:30 PM
  2. Replies: 2
    Last Post: 01-23-2018, 09:11 AM
  3. Replies: 9
    Last Post: 01-22-2015, 03:58 PM
  4. Replies: 0
    Last Post: 10-22-2012, 02:45 PM
  5. Replies: 1
    Last Post: 06-26-2012, 10:02 PM

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