Remove part of a string

  • Thread starter Thread starter Rob Roy CC
  • Start date Start date
R

Rob Roy CC

In one of my forms I import a list of file names from different folders on my
hard drive. My problem is that the import command imports the full file name
which includes the file path. The import command can not be changed so what I
want to do is use programming to remove everything to the left of the last
backslash "\" including the backslash. The list of file names are imported in
a subform and are recorded in a separate table.
Thanks for your help, Rob
 
Rob Roy CC said:
In one of my forms I import a list of file names from different folders on
my
hard drive. My problem is that the import command imports the full file
name
which includes the file path. The import command can not be changed so
what I
want to do is use programming to remove everything to the left of the last
backslash "\" including the backslash. The list of file names are imported
in
a subform and are recorded in a separate table.
Thanks for your help, Rob

Grab yourself some functions to deal with paths:

http://www.smccall.demon.co.uk/Strings.htm#PathFuncs

The one you need is FilePartOnly.

Debug.Print FilePartOnly("c:\windows\notepad.exe")

Result: notepad.exe
 
In one of my forms I import a list of file names from different folders on my
hard drive. My problem is that the import command imports the full file name
which includes the file path. The import command can not be changed so what I
want to do is use programming to remove everything to the left of the last
backslash "\" including the backslash. The list of file names are imported in
a subform and are recorded in a separate table.
Thanks for your help, Rob

=Mid([FullPath],InStrRev([FullPath],"\")+1)
 
Hi fredg,
I am a newie, where do I use this. The field is a bound text box. Can I use
it in a afterupdate procedure or a command button?
Thanks, Rob

fredg said:
In one of my forms I import a list of file names from different folders on my
hard drive. My problem is that the import command imports the full file name
which includes the file path. The import command can not be changed so what I
want to do is use programming to remove everything to the left of the last
backslash "\" including the backslash. The list of file names are imported in
a subform and are recorded in a separate table.
Thanks for your help, Rob

=Mid([FullPath],InStrRev([FullPath],"\")+1)
 
Hi fredg,
I am a newie, where do I use this. The field is a bound text box. Can I use
it in a afterupdate procedure or a command button?
Thanks, Rob

fredg said:
In one of my forms I import a list of file names from different folders on my
hard drive. My problem is that the import command imports the full file name
which includes the file path. The import command can not be changed so what I
want to do is use programming to remove everything to the left of the last
backslash "\" including the backslash. The list of file names are imported in
a subform and are recorded in a separate table.
Thanks for your help, Rob

=Mid([FullPath],InStrRev([FullPath],"\")+1)

If you wish to show just the file name without the path on a control
on your form, add an UNBOUND text control to your form.
Set it's control source to the above expression.
Change [FullPath] to whatever the actual name of the other control on
the form is that contains the full path to the file.

This control will always show just the file name and extension, i.e.
MyDatabase.mdb of whatever value, for example
"c:\MyBusinessFolder\MyBusiness.mdb is shown in the other control. You
don't have to do anything else to see it.
If you don't wish to see both the controls, just make the one with the
full path not visible.
 
Hi Fredg,
One more question, I need to record the info in a table so that I can use it
in other areas. If the field is unbound then how do I get the results into a
table?
Thanks, Rob

fredg said:
Hi fredg,
I am a newie, where do I use this. The field is a bound text box. Can I use
it in a afterupdate procedure or a command button?
Thanks, Rob

fredg said:
On Sun, 13 Apr 2008 19:39:00 -0700, Rob Roy CC wrote:

In one of my forms I import a list of file names from different folders on my
hard drive. My problem is that the import command imports the full file name
which includes the file path. The import command can not be changed so what I
want to do is use programming to remove everything to the left of the last
backslash "\" including the backslash. The list of file names are imported in
a subform and are recorded in a separate table.
Thanks for your help, Rob

=Mid([FullPath],InStrRev([FullPath],"\")+1)

If you wish to show just the file name without the path on a control
on your form, add an UNBOUND text control to your form.
Set it's control source to the above expression.
Change [FullPath] to whatever the actual name of the other control on
the form is that contains the full path to the file.

This control will always show just the file name and extension, i.e.
MyDatabase.mdb of whatever value, for example
"c:\MyBusinessFolder\MyBusiness.mdb is shown in the other control. You
don't have to do anything else to see it.
If you don't wish to see both the controls, just make the one with the
full path not visible.
 
Hi Fredg,
One more question, I need to record the info in a table so that I can use it
in other areas. If the field is unbound then how do I get the results into a
table?
Thanks, Rob

fredg said:
Hi fredg,
I am a newie, where do I use this. The field is a bound text box. Can I use
it in a afterupdate procedure or a command button?
Thanks, Rob

:

On Sun, 13 Apr 2008 19:39:00 -0700, Rob Roy CC wrote:

In one of my forms I import a list of file names from different folders on my
hard drive. My problem is that the import command imports the full file name
which includes the file path. The import command can not be changed so what I
want to do is use programming to remove everything to the left of the last
backslash "\" including the backslash. The list of file names are imported in
a subform and are recorded in a separate table.
Thanks for your help, Rob

=Mid([FullPath],InStrRev([FullPath],"\")+1)

If you wish to show just the file name without the path on a control
on your form, add an UNBOUND text control to your form.
Set it's control source to the above expression.
Change [FullPath] to whatever the actual name of the other control on
the form is that contains the full path to the file.

This control will always show just the file name and extension, i.e.
MyDatabase.mdb of whatever value, for example
"c:\MyBusinessFolder\MyBusiness.mdb is shown in the other control. You
don't have to do anything else to see it.
If you don't wish to see both the controls, just make the one with the
full path not visible.

Are you saving the full path in a table?
If so, then anytime you need the file name, just use the same
expression at that time. You don't save both.
 
Hi Fred,
Yes I do save the full path in a table but only because I have to in order
for the import function to work. The information that is important is the
file name, with its' extention. I need to generate various reports, queries
and other forms based on just the file name as the central item. So, in this
case, I need to record the file names in a table so that I can reference it.
Any help you can give in this matter is greatly appreciated. The help you
have already given works great!
Thanks, Rob


fredg said:
Hi Fredg,
One more question, I need to record the info in a table so that I can use it
in other areas. If the field is unbound then how do I get the results into a
table?
Thanks, Rob

fredg said:
On Mon, 14 Apr 2008 04:59:01 -0700, Rob Roy CC wrote:

Hi fredg,
I am a newie, where do I use this. The field is a bound text box. Can I use
it in a afterupdate procedure or a command button?
Thanks, Rob

:

On Sun, 13 Apr 2008 19:39:00 -0700, Rob Roy CC wrote:

In one of my forms I import a list of file names from different folders on my
hard drive. My problem is that the import command imports the full file name
which includes the file path. The import command can not be changed so what I
want to do is use programming to remove everything to the left of the last
backslash "\" including the backslash. The list of file names are imported in
a subform and are recorded in a separate table.
Thanks for your help, Rob

=Mid([FullPath],InStrRev([FullPath],"\")+1)
--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail


If you wish to show just the file name without the path on a control
on your form, add an UNBOUND text control to your form.
Set it's control source to the above expression.
Change [FullPath] to whatever the actual name of the other control on
the form is that contains the full path to the file.

This control will always show just the file name and extension, i.e.
MyDatabase.mdb of whatever value, for example
"c:\MyBusinessFolder\MyBusiness.mdb is shown in the other control. You
don't have to do anything else to see it.
If you don't wish to see both the controls, just make the one with the
full path not visible.

Are you saving the full path in a table?
If so, then anytime you need the file name, just use the same
expression at that time. You don't save both.
 
Hi Fred,
Yes I do save the full path in a table but only because I have to in order
for the import function to work. The information that is important is the
file name, with its' extention. I need to generate various reports, queries
and other forms based on just the file name as the central item. So, in this
case, I need to record the file names in a table so that I can reference it.
Any help you can give in this matter is greatly appreciated. The help you
have already given works great!
Thanks, Rob

"fredg" wrote: ** snipped **

What you can do is, after importing the data, run an update query to
remove the unwanted part of the full path field.
*** But then each time you import you must re-run the query.***

The Update query SQL would look like this:

Update YourTable set YourTable.FullPath =
Mid([FullPath],InStrRev([FullPath],"\")+1)
Where InStr([FullPath],"\")>0

The above will change the stored fullpath data to just the file name
when ever the FullPath contains a "\".

Change the Table and Field names to the actual Table and Field names
you are using.
 
Back
Top