+ Reply to Thread
Results 1 to 3 of 3

Argument not optional - Compile error

  1. #1
    Registered User
    Join Date
    07-26-2012
    Location
    Orlando
    MS-Off Ver
    Excel 2002
    Posts
    2

    Argument not optional - Compile error

    I am getting a "Argument not optional" error when trying to compile my vba. New to programming, so not really sure why. Here is the function I set up:

    Function esc(txt As String)

    esc = Trim(Replace(txt, """, " \ ""))

    End Function

    when I run it, Replace get highlighted in blue. I am implementing a vba file from instructions online to send my excel data to mysql dbase on godaddy. here are the instructions i was given:

    Once the ConnectDB Sub procedure is working, we will code the Sub procedure to perform data insertion. Before that, we need to create a data sanitizing function to escape single quotes before inserting them into the database. This is necessary because improper quote escaping will cause data insertion to fail.

    Here are the codes for the esc function that will escape single quotes from data to be inserted:

    Function esc(txt As String)
    esc = Trim(Replace(txt, "'", "\'"))
    End Function

    Here is the site with the full code I am using:
    http://www.heritage-tech.net/908/ins...cel-using-vba/
    Last edited by dsrfinancial; 07-26-2012 at 06:37 AM.

  2. #2
    Valued Forum Contributor smuzoen's Avatar
    Join Date
    10-28-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    610

    Re: Argument not optional - Compile error

    Please read the forum rules - please place code tags around your code - http://www.excelforum.com/forum-rule...rum-rules.html

    Your function that you are using is not what you were sent - you should be using Single quotes ' not " - your code is different to the code sent to you. You would call the code eg.
    Please Login or Register  to view this content.
    You would have to send your data that contains the single quote through the function to escape (\) then single quote
    Last edited by smuzoen; 07-26-2012 at 06:39 AM.
    Hope this helps.
    Anthony
    Pack my box with five dozen liquor jugs
    PS: Remember to mark your questions as Solved once you are satisfied. Please rate the answer(s) by selecting the Star in the lower left next to the Triangle. It is appreciated?

  3. #3
    Registered User
    Join Date
    07-26-2012
    Location
    Orlando
    MS-Off Ver
    Excel 2002
    Posts
    2

    Re: Argument not optional - Compile error

    Hey smuzoen,

    Thanks alot! That did get rid of the error. I will see if it works now.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1