Results 1 to 6 of 6
  1. #1
    jlawson258 is offline Novice
    Windows 8 Access 2013
    Join Date
    Mar 2015
    Posts
    9

    problem with setting variables for currency data types

    working in a function and trying to declare currency variables. I have ten variables declared. I then set each variable to 0 and then use FormatCurrency(1000000#, -1) for each variable.
    when I run the code the first 9 variables are set to $1,000,000.00. the tenth variable is set to 100000000. this is the section of the code:

    Dim filePath As String
    Dim s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11 As String
    Dim p, recreq, cpl, dona, c1, c2, civ, totbucks, lic, oth As Currency
    Dim chks, recs As Integer
    p = 0
    recreq = 0
    cpl = 0
    dona = 0
    c1 = 0
    c2 = 0
    civ = 0
    totbucks = 0
    lic = 0
    oth = 0


    p = FormatCurrency(1000000#, -1)
    recreq = FormatCurrency(1000000#, -1)
    cpl = FormatCurrency(1000000#, -1)


    dona = FormatCurrency(1000000#, -1)
    c1 = FormatCurrency(1000000#, -1)
    c2 = FormatCurrency(1000000#, -1)
    civ = FormatCurrency(1000000#, -1)
    totbucks = FormatCurrency(1000000#, -1)
    lic = FormatCurrency(1000000#, -1)
    oth = FormatCurrency(1000000#, -1)

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    What's the purpose of formatting a variable? I'd format in the destination, but I guess that's me. In your declarations:

    Dim p, recreq, cpl, dona, c1, c2, civ, totbucks, lic, oth As Currency

    You've declared 9 variables as Variant and 1 as Currency. In VBA you have to declare each:

    Dim p As Currency, recreq As Currency, ...
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    jlawson258 is offline Novice
    Windows 8 Access 2013
    Join Date
    Mar 2015
    Posts
    9

    problem with setting variables for currency data types

    I am trying to set variables for currency. I have declared 10 different variables. I also use the formatcurrency. When I run the code the first 9 variables are set to $1,000.000.00 and the tenth variable is set to 100000000. this is a copy of the code.

    Dim filePath As String
    Dim s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11 As String
    Dim p, recreq, cpl, dona, c1, c2, civ, totbucks, lic, oth As Currency
    Dim chks, recs As Integer
    p = 0
    recreq = 0
    cpl = 0
    dona = 0
    c1 = 0
    c2 = 0
    civ = 0
    totbucks = 0
    lic = 0
    oth = 0


    p = FormatCurrency(1000000#, -1)
    recreq = FormatCurrency(1000000#, -1)
    cpl = FormatCurrency(1000000#, -1)
    dona = FormatCurrency(1000000#, -1)
    c1 = FormatCurrency(1000000#, -1)
    c2 = FormatCurrency(1000000#, -1)
    civ = FormatCurrency(1000000#, -1)
    totbucks = FormatCurrency(1000000#, -1)
    lic = FormatCurrency(1000000#, -1)
    oth = FormatCurrency(1000000#, -1)


    thanks for any help you may have for me.

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    you set them all to VARIANT exept the last: oth .
    you must define the type for every variable:

    Dim p As Currency, recreq As Currency, cpl As Currency, dona As Currency , c1 As Currency, c2 As Currency, civ As Currency , totbucks As Currency, lic As urrency, oth As Currency

    (just because its on the same line, does not give it a defined type.)

  5. #5
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    post appears to be repeated here
    https://www.accessforums.net/showthread.php?t=82099

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Duplicate threads merged since both had replies.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Several The types of currency
    By azhar2006 in forum Access
    Replies: 7
    Last Post: 07-06-2022, 06:33 AM
  2. Setting object variables
    By Glenn_Suggs in forum Programming
    Replies: 4
    Last Post: 12-05-2018, 05:02 AM
  3. Replies: 7
    Last Post: 06-26-2016, 02:50 PM
  4. Setting global variables
    By Remster in forum Programming
    Replies: 1
    Last Post: 08-24-2011, 08:47 AM
  5. Currency Problem
    By EHittner in forum Access
    Replies: 1
    Last Post: 11-05-2009, 09:46 PM

Tags for this Thread

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