Results 1 to 6 of 6
  1. #1
    klnlsu is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Apr 2015
    Posts
    107

    getting compile error when trying to use replace function

    I've tried this function in a BeforeUpdate event and an AfterUpdate event and I get a compile error that says "Expected: =". My code is:



    Replace(CustItemNumberTxt,"'","")

    CustItemNumberTxt is the textbox on my current form that holds the string I am searching.

    I've also tried:

    Replace(CustItemNumberTxt,chr(39),"")

    I'm trying to edit single quotes (apostrophes) from my text.

  2. #2
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Please post your entire block of code so we can see how you are trying to use it.

  3. #3
    klnlsu is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Apr 2015
    Posts
    107
    Quote Originally Posted by JoeM View Post
    Please post your entire block of code so we can see how you are trying to use it.

    Private Sub CustItemNumberTxt_BeforeUpdate(Cancel As Integer)

    Replace(CustItemNumberTxt,"'","")
    Me.Refresh

    End Sub

    (FYI...I get the compile error as soon as I hit <ENTER> after typing in the Replace line)

  4. #4
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,388
    It requires an object.
    Code:
    MyField = Replace(CustItemNumberTxt,"'","")
    or

    Code:
    CustItemNumberTxt = Replace(CustItemNumberTxt,"'","")

  5. #5
    klnlsu is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Apr 2015
    Posts
    107
    Well, don't I feel foolish.

    Thanks for your help.

  6. #6
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,388
    Glad to help.
    I'll bet you'll remember that error message next time!

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

Similar Threads

  1. Compile Error: Sub/Function not defined
    By TheKillerMonkey in forum Programming
    Replies: 12
    Last Post: 04-18-2016, 01:48 PM
  2. Error with Replace Function
    By Juan4412 in forum Queries
    Replies: 1
    Last Post: 09-30-2012, 05:48 PM
  3. Compile Error Sub or function not defined
    By Ray67 in forum Reports
    Replies: 3
    Last Post: 07-02-2012, 04:11 PM
  4. Compile error: code or function not defined
    By GeorgeBrown in forum Access
    Replies: 1
    Last Post: 09-19-2011, 10:25 AM
  5. Compile error. Sub of function not defined
    By plavookins in forum Reports
    Replies: 7
    Last Post: 04-22-2011, 10:15 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