Results 1 to 3 of 3
  1. #1
    cherold is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2014
    Posts
    82

    I can't figure out why I'm getting a ByRef error from the compiler

    I'm getting a compiler error from a function call and I can't see why. I'm looping through an array of strings and passing the current string to a function.



    Code:
    Dim song_title, song_quote As String
    
        For Each Item In song_list          ' song list is an array of strings
                song_title = Item
                song_quote = ""
                song_quote = getSubSection(Item, "[", "]")    ' COMPILER ERROR!! "ByRef argument type mismatch" 
        Next
    The function itself, which returns a string is declared in this form:
    Code:
    Function getSubSection(SingleComposition As String, start_char As String, end_char As String)

    I tried passing the string variable instead of Item, but got the same error:

    Code:
    song_quote = getSubSection(song_title, "[", "]")
    I find that if I pass '"" & Item' as the argument the compiler doesn't complain, but I don't understand why it's necessary. If I'm passing a string, why do I need to add code to convince the compiler that it's a string?
    Code:
    song_quote = getSubSection("" & Item, "[", "]")

  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,518
    Shot in the dark, but try declaring song_title as String. Unspecified it's a Variant.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    the declare:
    Dim song_title, song_quote As String

    the line only sets songQuote to string.
    songTitle is variant.
    EVERY variable must be declared. Putting it on the same line does not declare a string.

    Dim song_title as string, song_quote As String

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

Similar Threads

  1. Replies: 3
    Last Post: 04-05-2018, 11:50 AM
  2. compiler error
    By Sheba in forum Forms
    Replies: 20
    Last Post: 10-03-2014, 12:41 PM
  3. Compiler error: Method or member not found
    By JosmithTwo in forum Programming
    Replies: 3
    Last Post: 11-26-2012, 07:10 AM
  4. byref argument type mismatch error
    By karuppasamy in forum Access
    Replies: 1
    Last Post: 06-22-2011, 09:37 AM
  5. ByRef error...never seen it before
    By jgelpi16 in forum Programming
    Replies: 1
    Last Post: 02-16-2011, 03:09 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