Results 1 to 6 of 6
  1. #1
    allenjasonbrown@gmail.com is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    44

    Silly error on a simple function call - help

    Hello all and thank you in advance. I am getting a "ByRef argument Type Mismatch" on the following code:


    Code:
    Sub testsub()
        
        vOrigNumber = 563200003
        Debug.Print vOrigNumber
        
        vSumDigits = DigitSum(vOrigNumber)
        Debug.Print vSumDigits
    End Sub
    
    
    Public Function DigitSum(NumberIn As String) As Integer
            Dim DigitLen As Integer, CheckLen As Integer
            Let DigitLen = Len(NumberIn)
            Let CheckLen = 1
            Let DigitSum = 0
            Do While CheckLen <= DigitLen
            DigitSum = DigitSum + CInt(Mid(NumberIn, CheckLen, 1))
            CheckLen = CheckLen + 1
            Loop
    End Function
    if I replace 'vOrigNumber' with 563200003 when calling the function, it works fine.

    Any idea why it does not like the variable???

    Thanks

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Try changing this one line:
    vSumDigits = DigitSum(vOrigNumber)
    ...to...
    vSumDigits = DigitSum(Cstr(vOrigNumber))

  3. #3
    allenjasonbrown@gmail.com is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    44
    Sweet! Thank you, that was it!

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Glad we could help. Do you understand why?

  5. #5
    allenjasonbrown@gmail.com is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    44
    Yes. I tried doing a CInt() because of the "as Integer" (which did not work) but after you posted your answer I see how I should have been looking at the "NumberIn As String".
    Thanks Again....have a great weekend!

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Right on the money! Have fun.

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

Similar Threads

  1. Help: ODBC call failed -952 SQLSTATE 57014 error
    By accessnewbie in forum Access
    Replies: 2
    Last Post: 02-02-2011, 01:01 PM
  2. Silly question
    By HelenP in forum Forms
    Replies: 1
    Last Post: 11-23-2010, 11:25 AM
  3. Need Help with Simple VB Function
    By nrage21 in forum Programming
    Replies: 2
    Last Post: 09-21-2010, 09:14 AM
  4. Replies: 5
    Last Post: 07-13-2010, 11:48 AM
  5. Replies: 4
    Last Post: 11-06-2009, 09:51 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