Results 1 to 7 of 7
  1. #1
    WAVP375 is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Dayton Ohio
    Posts
    171

    Elininating the " around the path of an image

    When using the 'Copt Path' option and pasting that path in a form it shows the " around the path. To eliminate the " I successfully use the 'ImagePath=Replace(ImagePath,Chr$(34), "")' command. This however leave a space where the leading " was. To eliminate the space I successfully use the 'LTrim(ImagePath)' command. In order save three text box data that has been entered in the form I simply save the record and do not close and reopen the form. Subsequent saves does not eliminate the leading space in ImagePath. How can I eliminate the leading space with out closing and reopening the form. Or is there an easy way to save the 3 text boxes and populate the form when reopend ?



    Thanks

  2. #2
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,474
    If you know it always has the " before and after the value, maybe use:

    Mid(ImagePath,2,Len(ImagePath)-1)

  3. #3
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Are the three text boxes bound to fields in the form's source table? If they are, then any changes made to them should be saved properly when you save the record, move to another record, or close the form.

    If they are not bound to table fields, then you will have to copy the edited values to the proper table field yourself with VBA.

    Do you have any code in the form which might be causing problems with the saves?

  4. #4
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,474
    Can you use nulls instead?
    'ImagePath=Replace(ImagePath,Chr$(34), null)

    The other thing is in the BeforeUpdate event on form, check those fields to see if there is data and if the leading char is " use code to remove them before it saves the data?

    If left(me.ImagePath1,1,") then Me.ImagePath1 = Mid(ImagePath1,2,Len(ImagePath1)-1)
    If left(me.ImagePath2,1,") then Me.ImagePath2 = Mid(ImagePath2,2,Len(ImagePath2)-1)

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

    When you replace a character with a the zero-length string ("") the replaced character is effectively removed - it does not count towards the length of a string.

    So, while len(" " & "A" & " ") = 3 (with blanks), len("" & "A" & "") = 1 (with zero-length 'characters')

    Asc("") results in an error.

  6. #6
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,474
    Yep just giving options. I was thinking if the pasted text is "c:\folder\file.txt" (quotes included), then maybe he can skip the Replace and Trim and in BeforeUpdate on form, remove those " with:
    If left(me.ImagePath1,1,") then Me.ImagePath1 = Mid(ImagePath1,2,Len(ImagePath1)-1)

    Or if needing to remove leading space before saving:
    If left(me.ImagePath1,1," ") then Me.ImagePath1 = Mid(ImagePath1,2,)

  7. #7
    WAVP375 is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Dayton Ohio
    Posts
    171
    Thanks folks the following code seems to do what I need.


    'Remove leading " or space from the text path
    ImagePath = Mid(ImagePath, 2, Len(ImagePath) - 1)

    'Remove trailing " from the text path
    ImagePath = Mid(ImagePath, 1, Len(ImagePath) - 1)

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

Similar Threads

  1. Replies: 5
    Last Post: 08-27-2016, 11:09 AM
  2. Copying the path and file name of an image
    By WAVP375 in forum Access
    Replies: 4
    Last Post: 07-27-2016, 08:52 AM
  3. Replies: 10
    Last Post: 01-09-2014, 03:00 AM
  4. Replies: 1
    Last Post: 05-14-2013, 11:49 AM
  5. Replies: 1
    Last Post: 04-12-2013, 07:56 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