Results 1 to 12 of 12
  1. #1
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496

    Convert custom field with replace() to string

    I have made a field in the query with a replace() function

    so



    Expr: replace([field],"chr(10)"," Found One ")

    for some reason Expr: doesn't return as a string?!

    so I can't do any criteria searches

    If I try converting to str() I also get an error.

    help

  2. #2
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    I've used this to get around my issue but I still don't know the reason.

    Click image for larger version. 

Name:	Capture.PNG 
Views:	12 
Size:	2.2 KB 
ID:	17697

  3. #3
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    You have an error in this expression:

    Expr: replace([field],"chr(10)"," Found One ")

    Chr(10) should not be in quotation marks. Putting it in quotes makes it just a string which happens to be "chr(10)", so the replace looks for that string, not a Carriage-return (or is it line-feed?) character.

    HTH

    John

  4. #4
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by John_G View Post
    You have an error in this expression:

    Expr: replace([field],"chr(10)"," Found One ")

    Chr(10) should not be in quotation marks. Putting it in quotes makes it just a string which happens to be "chr(10)", so the replace looks for that string, not a Carriage-return (or is it line-feed?) character.

    HTH

    John
    Yeah I checked that - same error

    (I made that error when typing the post only)

    Click image for larger version. 

Name:	Capture.PNG 
Views:	12 
Size:	2.8 KB 
ID:	17699

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Can you tell us exactly what you are trying to do? Perhaps a sample of the input and the intended output.

    Here's the details on the Replace function

  6. #6
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Hi -

    I am having no difficulty with the replace function - it does exactly what it should with chr(10).

    Are you getting an error message, and if so what does it say?

    In your example, if [SchoolPostalAddress] is Null, you will get an error "Invalid Use of Null"

    Using Nz([SchoolPostalAddress],"") will prevent that error.

    John

  7. #7
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    @John_G

    I agree, I understand Replace but what is with the criteria in the query grid?

  8. #8
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    @orange -

    Sorry - I was responding to the OP.

    @Ruegen -

    Orange raises a good point - what does (or should) the criteria do? From what I can see, it will give you only those records with more than one line in the address.

    John

  9. #9
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by John_G View Post
    @orange -

    Sorry - I was responding to the OP.

    @Ruegen -

    Orange raises a good point - what does (or should) the criteria do? From what I can see, it will give you only those records with more than one line in the address.

    John
    It's an old database where users have put new lines when entering data that I have to remove (they are hidden from view on forms otherwise on single line text boxes).

    I'll try nz() as it might be that

  10. #10
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Hi -

    If all you want to do is replace all the Chr(10) "characters" in that field, for all records, you can do it with one SQL statement.

    currentdb.execute "Update tablename set [SchoolPostalAddress] = Replace([SchoolPostalAddress],chr(10),' ') where [schoolpostaladdress] is not null", dbfailonerror

    The "where" part limits it to records where [SchoolPostalAddress] has data in it.

    Change tablename to the name of your table. You could paste the bold text into the SQL view of query design.

    John

  11. #11
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Sounds good - I could simply put not is null as a criteria on [schooladdress] and that way the error won't happen I guess - will have to try when I get back to work

    I need to remember these things when I get errors

  12. #12
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Hiya everyone

    Yes it was indeed the null causing the error

    Thanks for your help!

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

Similar Threads

  1. Automatically replace NULL with zero string
    By tylerg11 in forum Access
    Replies: 13
    Last Post: 09-16-2013, 04:34 PM
  2. Replies: 1
    Last Post: 03-25-2012, 01:53 PM
  3. Issue Using Replace in SQL String
    By starryNight in forum Programming
    Replies: 15
    Last Post: 06-03-2011, 01:24 PM
  4. Replace a string/text in ms-access db
    By anziga in forum Queries
    Replies: 4
    Last Post: 12-31-2010, 06:40 PM
  5. replace characters in a string
    By blazixinfo@yahoo.com in forum Access
    Replies: 6
    Last Post: 08-06-2009, 03:36 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