InStrRev

J

Jimmy G

Can anyone show me the proper use of InStrRev to limit the
full path name to just the filename?
 
D

Dan Artuso

Hi,
Here's what I use:

Public Function GetFileNameFromFullPath(fullPath As String) As String
GetFileNameFromFullPath = Right(fullPath, Len(fullPath) - InStrRev(fullPath,
"\", , vbTextCompare))
End Function

You may want to add some validation/error handling.
HTH
Dan Artuso, MVP
 
J

Jimmy G

Is there some more code to go with this? I copied the
function into my form and I get an error while compiling.
 
D

Dan Artuso

Hi,
Works fine here. Your newsreader may be wrapping some of the lines.
this line:
**GetFileNameFromFullPath = Right(fullPath, Len(fullPath) -
InStrRev(fullPath,"\", , vbTextCompare))**

should all be on one line.

HTH
Dan Artuso, MVP
 
J

Jeff Conrad

Or Jimmy could be using Access 97???
I don't believe InStrRev exists in 97, correct?
 
G

Guest

I am using Access 2003. It was wrapped. I put the
statement on one line and I get the message "Compile
error. Expected: end of statement. I have
another 'getFileName' function in the code. Could that be
causing some conflict?
 
J

Jimmy

Dan,
I found the problem. Typing errors. It is now
compiling. How do I call it and connect it to the text
field on my form?
 
J

Jimmy G

This is the code I've inserted:
Public Function GetFileNameFromFullPath(PhotoLocation As
String) As String
GetFileNameFromFullPath = Right(PhotoLocation, Len
(PhotoLocation) - InStrRev(PhotoLocation, "\", ,
vbTextCompare))
Me.PhotoName = GetFileNameFromFullPath(PhotoLocation)
End Function

In the above, 'PhotoLocation' is the name of the text
field that contains the full path; 'PhotoName' is the name
of the field that I want to show the trimmed file name. I
don't know what I'm doing wrong.
 
D

Douglas J. Steele

You've got a call to the function inside of the function itself, making a
recursive function!

I'm assuming that the function should be:

Public Function GetFileNameFromFullPath(PhotoLocation As String) As String
GetFileNameFromFullPath = Right(PhotoLocation, Len(PhotoLocation) - _
InStrRev(PhotoLocation, "\", vbTextCompare))
End Function

(Note that you have one too many commas)

Then, somewhere in the code behind your form, you need to have the line

Me.PhotoName = GetFileNameFromFullPath(PhotoLocation)
 
G

Guest

The following is declared in the code for the page:

Private Function GetFileNameFromFullPath(PhotoLocationAs
String) As String
GetFileNameFromFullPath = Right(PhotoLocation, Len
(PhotoLocation) - InStrRev(PhotoLocation, "\",
vbTextCompare))
Me.[PhotoName] = GetFileNameFromFullPath(PhotoLocation)
End Function

Next, under Private Sub Form_Current(), this line appears:
Me.[PhotoName] = GetFileNameFromFullPath(PhotoLocation)

The Line "GetFileName.........Compare))" is all on one
line. I removed the extra comma. Still the PhotoName
field is blank. What should the 'Control Source' for the
PhotoName be set to?
 
D

Douglas J. Steele

I don't think you read my answer very closely.

The last line in your function is

Me.[PhotoName] = GetFileNameFromFullPath(PhotoLocation)

Take that out of the function. It's wrong to have it there.



--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)



The following is declared in the code for the page:

Private Function GetFileNameFromFullPath(PhotoLocationAs
String) As String
GetFileNameFromFullPath = Right(PhotoLocation, Len
(PhotoLocation) - InStrRev(PhotoLocation, "\",
vbTextCompare))
Me.[PhotoName] = GetFileNameFromFullPath(PhotoLocation)
End Function

Next, under Private Sub Form_Current(), this line appears:
Me.[PhotoName] = GetFileNameFromFullPath(PhotoLocation)

The Line "GetFileName.........Compare))" is all on one
line. I removed the extra comma. Still the PhotoName
field is blank. What should the 'Control Source' for the
PhotoName be set to?
-----Original Message-----
You've got a call to the function inside of the function itself, making a
recursive function!

I'm assuming that the function should be:

Public Function GetFileNameFromFullPath(PhotoLocation As String) As String
GetFileNameFromFullPath = Right(PhotoLocation, Len (PhotoLocation) - _
InStrRev(PhotoLocation, "\", vbTextCompare))
End Function

(Note that you have one too many commas)

Then, somewhere in the code behind your form, you need to have the line

Me.PhotoName = GetFileNameFromFullPath(PhotoLocation)

--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)






.
 
G

Guest

I failed to mention that. I placed that line in the
OnCurrent event of the form. And still the PhotoName
field is blank. How should I set the 'ControlSource'
property of the PhotoName field?

-----Original Message-----
I don't think you read my answer very closely.

The last line in your function is

Me.[PhotoName] = GetFileNameFromFullPath (PhotoLocation)

Take that out of the function. It's wrong to have it there.



--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)



The following is declared in the code for the page:

Private Function GetFileNameFromFullPath(PhotoLocationAs
String) As String
GetFileNameFromFullPath = Right(PhotoLocation, Len
(PhotoLocation) - InStrRev(PhotoLocation, "\",
vbTextCompare))
Me.[PhotoName] = GetFileNameFromFullPath (PhotoLocation)
End Function

Next, under Private Sub Form_Current(), this line appears:
Me.[PhotoName] = GetFileNameFromFullPath(PhotoLocation)

The Line "GetFileName.........Compare))" is all on one
line. I removed the extra comma. Still the PhotoName
field is blank. What should the 'Control Source' for the
PhotoName be set to?
-----Original Message-----
You've got a call to the function inside of the
function
itself, making a
recursive function!

I'm assuming that the function should be:

Public Function GetFileNameFromFullPath(PhotoLocation
As
String) As String
GetFileNameFromFullPath = Right(PhotoLocation, Len (PhotoLocation) - _
InStrRev(PhotoLocation, "\", vbTextCompare))
End Function

(Note that you have one too many commas)

Then, somewhere in the code behind your form, you need
to
have the line
Me.PhotoName = GetFileNameFromFullPath(PhotoLocation)

--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)



"Jimmy G" <[email protected]> wrote
in
message
This is the code I've inserted:
Public Function GetFileNameFromFullPath (PhotoLocation As
String) As String
GetFileNameFromFullPath = Right(PhotoLocation, Len
(PhotoLocation) - InStrRev(PhotoLocation, "\", ,
vbTextCompare))
Me.PhotoName = GetFileNameFromFullPath (PhotoLocation)
End Function

In the above, 'PhotoLocation' is the name of the text
field that contains the full path; 'PhotoName' is the name
of the field that I want to show the trimmed file name. I
don't know what I'm doing wrong.

-----Original Message-----
Hi,
Something like this:
Me.yourField = GetFileNameFromFullPath("yourPath")

--
HTH
Dan Artuso, MVP


message
Dan,
I found the problem. Typing errors. It is now
compiling. How do I call it and connect it to the text
field on my form?
-----Original Message-----
Hi,
Here's what I use:

Public Function GetFileNameFromFullPath(fullPath As
String) As String
GetFileNameFromFullPath = Right(fullPath, Len
(fullPath) -
InStrRev(fullPath,
"\", , vbTextCompare))
End Function

You may want to add some validation/error handling.
HTH
Dan Artuso, MVP

in
message
Can anyone show me the proper use of InStrRev to
limit
the
full path name to just the filename?


.



.



.


.
 
D

Douglas J. Steele

If you've got the code Me.[PhotoName] =
GetFileNameFromFullPath(PhotoLocation) in Form_Current(), you don't need to
set a ControlSource property for the PhotName field.

Alternatively, don't have the code in Form_Current(), and you can put
=GetFileNameFromFullPath(PhotoLocation) as the ControlSource.

In either case, I'm assuming there's another field on your form named
PhotoLocation.


--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)



I failed to mention that. I placed that line in the
OnCurrent event of the form. And still the PhotoName
field is blank. How should I set the 'ControlSource'
property of the PhotoName field?

-----Original Message-----
I don't think you read my answer very closely.

The last line in your function is

Me.[PhotoName] = GetFileNameFromFullPath (PhotoLocation)

Take that out of the function. It's wrong to have it there.



--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)



The following is declared in the code for the page:

Private Function GetFileNameFromFullPath(PhotoLocationAs
String) As String
GetFileNameFromFullPath = Right(PhotoLocation, Len
(PhotoLocation) - InStrRev(PhotoLocation, "\",
vbTextCompare))
Me.[PhotoName] = GetFileNameFromFullPath (PhotoLocation)
End Function

Next, under Private Sub Form_Current(), this line appears:
Me.[PhotoName] = GetFileNameFromFullPath(PhotoLocation)

The Line "GetFileName.........Compare))" is all on one
line. I removed the extra comma. Still the PhotoName
field is blank. What should the 'Control Source' for the
PhotoName be set to?
-----Original Message-----
You've got a call to the function inside of the function
itself, making a
recursive function!

I'm assuming that the function should be:

Public Function GetFileNameFromFullPath(PhotoLocation As
String) As String
GetFileNameFromFullPath = Right(PhotoLocation, Len
(PhotoLocation) - _
InStrRev(PhotoLocation, "\", vbTextCompare))
End Function

(Note that you have one too many commas)

Then, somewhere in the code behind your form, you need to
have the line

Me.PhotoName = GetFileNameFromFullPath(PhotoLocation)

--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)



message
This is the code I've inserted:
Public Function GetFileNameFromFullPath (PhotoLocation As
String) As String
GetFileNameFromFullPath = Right(PhotoLocation, Len
(PhotoLocation) - InStrRev(PhotoLocation, "\", ,
vbTextCompare))
Me.PhotoName = GetFileNameFromFullPath
(PhotoLocation)
End Function

In the above, 'PhotoLocation' is the name of the text
field that contains the full path; 'PhotoName' is the
name
of the field that I want to show the trimmed file
name. I
don't know what I'm doing wrong.

-----Original Message-----
Hi,
Something like this:
Me.yourField = GetFileNameFromFullPath("yourPath")

--
HTH
Dan Artuso, MVP


message
Dan,
I found the problem. Typing errors. It is now
compiling. How do I call it and connect it to the
text
field on my form?
-----Original Message-----
Hi,
Here's what I use:

Public Function GetFileNameFromFullPath(fullPath As
String) As String
GetFileNameFromFullPath = Right(fullPath, Len
(fullPath) -
InStrRev(fullPath,
"\", , vbTextCompare))
End Function

You may want to add some validation/error handling.
HTH
Dan Artuso, MVP

"Jimmy G" <[email protected]>
wrote
in
message
Can anyone show me the proper use of InStrRev to
limit
the
full path name to just the filename?


.



.



.


.
 
J

Jimmy G

Here is my code as it is written:

Option Compare Database
Dim path As String

Public Function GetFileNameFromFullPath(PhotoLocation As
String) As String
GetFileNameFromFullPath = Right(PhotoLocation, Len
(PhotoLocation) - InStrRev(PhotoLocation, "\",
vbTextCompare))
End Function

Private Sub Form_Current()
path = CurrentProject.path
On Error Resume Next
Me!Image.Picture = Nz(Me.PhotoLocation, "")
If Err = 2220 Then Me.Image.Picture = ""
Me.PhotoName = GetFileNameFromFullPath(PhotoLocation)
End Sub

Yes, the field 'PhotoLocation' contains the full path for
the picture. I want the field 'PhotoName' to show only
the file name without the full path. I am certainly
greatful for all the time you guys are spending with me on
this.

-----Original Message-----
If you've got the code Me.[PhotoName] =
GetFileNameFromFullPath(PhotoLocation) in Form_Current(), you don't need to
set a ControlSource property for the PhotName field.

Alternatively, don't have the code in Form_Current(), and you can put
=GetFileNameFromFullPath(PhotoLocation) as the ControlSource.

In either case, I'm assuming there's another field on your form named
PhotoLocation.


--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)



I failed to mention that. I placed that line in the
OnCurrent event of the form. And still the PhotoName
field is blank. How should I set the 'ControlSource'
property of the PhotoName field?

-----Original Message-----
I don't think you read my answer very closely.

The last line in your function is

Me.[PhotoName] = GetFileNameFromFullPath (PhotoLocation)

Take that out of the function. It's wrong to have it there.



--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)



The following is declared in the code for the page:

Private Function GetFileNameFromFullPath (PhotoLocationAs
String) As String
GetFileNameFromFullPath = Right(PhotoLocation, Len
(PhotoLocation) - InStrRev(PhotoLocation, "\",
vbTextCompare))
Me.[PhotoName] = GetFileNameFromFullPath (PhotoLocation)
End Function

Next, under Private Sub Form_Current(), this line appears:
Me.[PhotoName] = GetFileNameFromFullPath (PhotoLocation)

The Line "GetFileName.........Compare))" is all on one
line. I removed the extra comma. Still the PhotoName
field is blank. What should the 'Control Source' for the
PhotoName be set to?
-----Original Message-----
You've got a call to the function inside of the function
itself, making a
recursive function!

I'm assuming that the function should be:

Public Function GetFileNameFromFullPath
(PhotoLocation
As
String) As String
GetFileNameFromFullPath = Right(PhotoLocation, Len
(PhotoLocation) - _
InStrRev(PhotoLocation, "\", vbTextCompare))
End Function

(Note that you have one too many commas)

Then, somewhere in the code behind your form, you
need
to
have the line

Me.PhotoName = GetFileNameFromFullPath (PhotoLocation)

--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)



"Jimmy G" <[email protected]>
wrote
in
message
This is the code I've inserted:
Public Function GetFileNameFromFullPath (PhotoLocation As
String) As String
GetFileNameFromFullPath = Right(PhotoLocation, Len
(PhotoLocation) - InStrRev(PhotoLocation, "\", ,
vbTextCompare))
Me.PhotoName = GetFileNameFromFullPath
(PhotoLocation)
End Function

In the above, 'PhotoLocation' is the name of the text
field that contains the full path; 'PhotoName' is the
name
of the field that I want to show the trimmed file
name. I
don't know what I'm doing wrong.

-----Original Message-----
Hi,
Something like this:
Me.yourField = GetFileNameFromFullPath ("yourPath")

--
HTH
Dan Artuso, MVP


"Jimmy" <[email protected]>
wrote
in
message
Dan,
I found the problem. Typing errors. It is now
compiling. How do I call it and connect it to the
text
field on my form?
-----Original Message-----
Hi,
Here's what I use:

Public Function GetFileNameFromFullPath
(fullPath
As
String) As String
GetFileNameFromFullPath = Right(fullPath, Len
(fullPath) -
InStrRev(fullPath,
"\", , vbTextCompare))
End Function

You may want to add some validation/error handling.
HTH
Dan Artuso, MVP

"Jimmy G"
wrote
in
message
Can anyone show me the proper use of
InStrRev
to
limit
the
full path name to just the filename?


.



.



.



.


.
 
D

dan artuso

Hi,
Try stepping through the code. Place a breakpoint on the 1st line of your Form_Current
event (click in the left hand margin in the VB editor on that line). Now when the event fires,
you'll be taken to the editor and you can press F8 to step through the code. Hover your cursor over
the variabls to see their value.

--
HTH
Dan Artuso, MVP


Jimmy G said:
Here is my code as it is written:

Option Compare Database
Dim path As String

Public Function GetFileNameFromFullPath(PhotoLocation As
String) As String
GetFileNameFromFullPath = Right(PhotoLocation, Len
(PhotoLocation) - InStrRev(PhotoLocation, "\",
vbTextCompare))
End Function

Private Sub Form_Current()
path = CurrentProject.path
On Error Resume Next
Me!Image.Picture = Nz(Me.PhotoLocation, "")
If Err = 2220 Then Me.Image.Picture = ""
Me.PhotoName = GetFileNameFromFullPath(PhotoLocation)
End Sub

Yes, the field 'PhotoLocation' contains the full path for
the picture. I want the field 'PhotoName' to show only
the file name without the full path. I am certainly
greatful for all the time you guys are spending with me on
this.

-----Original Message-----
If you've got the code Me.[PhotoName] =
GetFileNameFromFullPath(PhotoLocation) in Form_Current(), you don't need to
set a ControlSource property for the PhotName field.

Alternatively, don't have the code in Form_Current(), and you can put
=GetFileNameFromFullPath(PhotoLocation) as the ControlSource.

In either case, I'm assuming there's another field on your form named
PhotoLocation.


--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)



I failed to mention that. I placed that line in the
OnCurrent event of the form. And still the PhotoName
field is blank. How should I set the 'ControlSource'
property of the PhotoName field?


-----Original Message-----
I don't think you read my answer very closely.

The last line in your function is

Me.[PhotoName] = GetFileNameFromFullPath
(PhotoLocation)

Take that out of the function. It's wrong to have it
there.



--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)



The following is declared in the code for the page:

Private Function GetFileNameFromFullPath (PhotoLocationAs
String) As String
GetFileNameFromFullPath = Right(PhotoLocation, Len
(PhotoLocation) - InStrRev(PhotoLocation, "\",
vbTextCompare))
Me.[PhotoName] = GetFileNameFromFullPath
(PhotoLocation)
End Function

Next, under Private Sub Form_Current(), this line
appears:
Me.[PhotoName] = GetFileNameFromFullPath (PhotoLocation)

The Line "GetFileName.........Compare))" is all on one
line. I removed the extra comma. Still the PhotoName
field is blank. What should the 'Control Source' for
the
PhotoName be set to?
-----Original Message-----
You've got a call to the function inside of the
function
itself, making a
recursive function!

I'm assuming that the function should be:

Public Function GetFileNameFromFullPath (PhotoLocation
As
String) As String
GetFileNameFromFullPath = Right(PhotoLocation, Len
(PhotoLocation) - _
InStrRev(PhotoLocation, "\", vbTextCompare))
End Function

(Note that you have one too many commas)

Then, somewhere in the code behind your form, you need
to
have the line

Me.PhotoName = GetFileNameFromFullPath (PhotoLocation)

--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)



in
message
This is the code I've inserted:
Public Function GetFileNameFromFullPath
(PhotoLocation As
String) As String
GetFileNameFromFullPath = Right(PhotoLocation,
Len
(PhotoLocation) - InStrRev(PhotoLocation, "\", ,
vbTextCompare))
Me.PhotoName = GetFileNameFromFullPath
(PhotoLocation)
End Function

In the above, 'PhotoLocation' is the name of the text
field that contains the full path; 'PhotoName' is the
name
of the field that I want to show the trimmed file
name. I
don't know what I'm doing wrong.

-----Original Message-----
Hi,
Something like this:
Me.yourField = GetFileNameFromFullPath ("yourPath")

--
HTH
Dan Artuso, MVP


in
message
Dan,
I found the problem. Typing errors. It is now
compiling. How do I call it and connect it to the
text
field on my form?
-----Original Message-----
Hi,
Here's what I use:

Public Function GetFileNameFromFullPath (fullPath
As
String) As String
GetFileNameFromFullPath = Right(fullPath, Len
(fullPath) -
InStrRev(fullPath,
"\", , vbTextCompare))
End Function

You may want to add some validation/error
handling.
HTH
Dan Artuso, MVP

"Jimmy G"
wrote
in
message
Can anyone show me the proper use of InStrRev
to
limit
the
full path name to just the filename?


.



.



.



.


.
 
J

Jimmy G

I stepped through code as suggested and found that
initially the 'GetFileNameFromFullPath' equals
nothing, "". After stepping through the function,
the 'GetFileNameFromFullPath' equals the full path of the
file. Apparently the InStrRev function (ie. Public
Function GetFileNameFromFullPath(PhotoLocation As String)
As String
GetFileNameFromFullPath = Right(PhotoLocation, Len
(PhotoLocation) - InStrRev(PhotoLocation, "\",
vbTextCompare))
End Function

still has some problems. Next I stepped through the
OnCurrent() property, the 'PhotoName' field shows the full
path (D:\My Documents\Photos\Photo07.JPG) when I hover
over it.

-----Original Message-----
Hi,
Try stepping through the code. Place a breakpoint on the 1st line of your Form_Current
event (click in the left hand margin in the VB editor on
that line). Now when the event fires,
you'll be taken to the editor and you can press F8 to
step through the code. Hover your cursor over
the variabls to see their value.

--
HTH
Dan Artuso, MVP


Here is my code as it is written:

Option Compare Database
Dim path As String

Public Function GetFileNameFromFullPath(PhotoLocation As
String) As String
GetFileNameFromFullPath = Right(PhotoLocation, Len
(PhotoLocation) - InStrRev(PhotoLocation, "\",
vbTextCompare))
End Function

Private Sub Form_Current()
path = CurrentProject.path
On Error Resume Next
Me!Image.Picture = Nz(Me.PhotoLocation, "")
If Err = 2220 Then Me.Image.Picture = ""
Me.PhotoName = GetFileNameFromFullPath (PhotoLocation)
End Sub

Yes, the field 'PhotoLocation' contains the full path for
the picture. I want the field 'PhotoName' to show only
the file name without the full path. I am certainly
greatful for all the time you guys are spending with me on
this.

-----Original Message-----
If you've got the code Me.[PhotoName] =
GetFileNameFromFullPath(PhotoLocation) in Form_Current
(),
you don't need to
set a ControlSource property for the PhotName field.

Alternatively, don't have the code in Form_Current(),
and
you can put
=GetFileNameFromFullPath(PhotoLocation) as the ControlSource.

In either case, I'm assuming there's another field on your form named
PhotoLocation.


--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)



I failed to mention that. I placed that line in the
OnCurrent event of the form. And still the PhotoName
field is blank. How should I set the 'ControlSource'
property of the PhotoName field?


-----Original Message-----
I don't think you read my answer very closely.

The last line in your function is

Me.[PhotoName] = GetFileNameFromFullPath
(PhotoLocation)

Take that out of the function. It's wrong to have it
there.



--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)



The following is declared in the code for the page:

Private Function GetFileNameFromFullPath (PhotoLocationAs
String) As String
GetFileNameFromFullPath = Right(PhotoLocation, Len
(PhotoLocation) - InStrRev(PhotoLocation, "\",
vbTextCompare))
Me.[PhotoName] = GetFileNameFromFullPath
(PhotoLocation)
End Function

Next, under Private Sub Form_Current(), this line
appears:
Me.[PhotoName] = GetFileNameFromFullPath (PhotoLocation)

The Line "GetFileName.........Compare))" is all on one
line. I removed the extra comma. Still the PhotoName
field is blank. What should the 'Control Source' for
the
PhotoName be set to?
-----Original Message-----
You've got a call to the function inside of the
function
itself, making a
recursive function!

I'm assuming that the function should be:

Public Function GetFileNameFromFullPath (PhotoLocation
As
String) As String
GetFileNameFromFullPath = Right
(PhotoLocation,
Len
(PhotoLocation) - _
InStrRev(PhotoLocation, "\", vbTextCompare))
End Function

(Note that you have one too many commas)

Then, somewhere in the code behind your form, you need
to
have the line

Me.PhotoName = GetFileNameFromFullPath (PhotoLocation)

--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)



in
message
This is the code I've inserted:
Public Function GetFileNameFromFullPath
(PhotoLocation As
String) As String
GetFileNameFromFullPath = Right (PhotoLocation,
Len
(PhotoLocation) - InStrRev (PhotoLocation, "\", ,
vbTextCompare))
Me.PhotoName = GetFileNameFromFullPath
(PhotoLocation)
End Function

In the above, 'PhotoLocation' is the name of
the
text
field that contains the full path; 'PhotoName'
is
the
name
of the field that I want to show the trimmed file
name. I
don't know what I'm doing wrong.

-----Original Message-----
Hi,
Something like this:
Me.yourField = GetFileNameFromFullPath ("yourPath")

--
HTH
Dan Artuso, MVP


in
message
Dan,
I found the problem. Typing errors. It is now
compiling. How do I call it and connect it
to
the
text
field on my form?
-----Original Message-----
Hi,
Here's what I use:

Public Function GetFileNameFromFullPath (fullPath
As
String) As String
GetFileNameFromFullPath = Right(fullPath, Len
(fullPath) -
InStrRev(fullPath,
"\", , vbTextCompare))
End Function

You may want to add some validation/error
handling.
HTH
Dan Artuso, MVP

"Jimmy G"
wrote
in
message
[email protected]...
Can anyone show me the proper use of InStrRev
to
limit
the
full path name to just the filename?


.



.



.



.



.


.
 
D

dan artuso

Well, I don't know what to tell you. It definitely works here.
This is what I get when testing in the Immediate window:

?GetFileNameFromFullPath("D:\My Documents\Photos\Photo07.JPG")
Photo07.JPG


Why don't you move the function to a standard module, press ctl-G
(which will bring up the immediate window) and then enter:
?GetFileNameFromFullPath("D:\My Documents\Photos\Photo07.JPG")

press Return and see if you get the same result I did.
--
HTH
Dan Artuso, MVP


Jimmy G said:
I stepped through code as suggested and found that
initially the 'GetFileNameFromFullPath' equals
nothing, "". After stepping through the function,
the 'GetFileNameFromFullPath' equals the full path of the
file. Apparently the InStrRev function (ie. Public
Function GetFileNameFromFullPath(PhotoLocation As String)
As String
GetFileNameFromFullPath = Right(PhotoLocation, Len
(PhotoLocation) - InStrRev(PhotoLocation, "\",
vbTextCompare))
End Function

still has some problems. Next I stepped through the
OnCurrent() property, the 'PhotoName' field shows the full
path (D:\My Documents\Photos\Photo07.JPG) when I hover
over it.

-----Original Message-----
Hi,
Try stepping through the code. Place a breakpoint on the 1st line of your Form_Current
event (click in the left hand margin in the VB editor on
that line). Now when the event fires,
you'll be taken to the editor and you can press F8 to
step through the code. Hover your cursor over
the variabls to see their value.

--
HTH
Dan Artuso, MVP


Here is my code as it is written:

Option Compare Database
Dim path As String

Public Function GetFileNameFromFullPath(PhotoLocation As
String) As String
GetFileNameFromFullPath = Right(PhotoLocation, Len
(PhotoLocation) - InStrRev(PhotoLocation, "\",
vbTextCompare))
End Function

Private Sub Form_Current()
path = CurrentProject.path
On Error Resume Next
Me!Image.Picture = Nz(Me.PhotoLocation, "")
If Err = 2220 Then Me.Image.Picture = ""
Me.PhotoName = GetFileNameFromFullPath (PhotoLocation)
End Sub

Yes, the field 'PhotoLocation' contains the full path for
the picture. I want the field 'PhotoName' to show only
the file name without the full path. I am certainly
greatful for all the time you guys are spending with me on
this.


-----Original Message-----
If you've got the code Me.[PhotoName] =
GetFileNameFromFullPath(PhotoLocation) in Form_Current (),
you don't need to
set a ControlSource property for the PhotName field.

Alternatively, don't have the code in Form_Current(), and
you can put
=GetFileNameFromFullPath(PhotoLocation) as the
ControlSource.

In either case, I'm assuming there's another field on
your form named
PhotoLocation.


--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)



I failed to mention that. I placed that line in the
OnCurrent event of the form. And still the PhotoName
field is blank. How should I set the 'ControlSource'
property of the PhotoName field?


-----Original Message-----
I don't think you read my answer very closely.

The last line in your function is

Me.[PhotoName] = GetFileNameFromFullPath
(PhotoLocation)

Take that out of the function. It's wrong to have it
there.



--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)



The following is declared in the code for the page:

Private Function GetFileNameFromFullPath
(PhotoLocationAs
String) As String
GetFileNameFromFullPath = Right(PhotoLocation,
Len
(PhotoLocation) - InStrRev(PhotoLocation, "\",
vbTextCompare))
Me.[PhotoName] = GetFileNameFromFullPath
(PhotoLocation)
End Function

Next, under Private Sub Form_Current(), this line
appears:
Me.[PhotoName] = GetFileNameFromFullPath
(PhotoLocation)

The Line "GetFileName.........Compare))" is all on
one
line. I removed the extra comma. Still the PhotoName
field is blank. What should the 'Control Source' for
the
PhotoName be set to?
-----Original Message-----
You've got a call to the function inside of the
function
itself, making a
recursive function!

I'm assuming that the function should be:

Public Function GetFileNameFromFullPath
(PhotoLocation
As
String) As String
GetFileNameFromFullPath = Right (PhotoLocation,
Len
(PhotoLocation) - _
InStrRev(PhotoLocation, "\",
vbTextCompare))
End Function

(Note that you have one too many commas)

Then, somewhere in the code behind your form, you
need
to
have the line

Me.PhotoName = GetFileNameFromFullPath
(PhotoLocation)

--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)



"Jimmy G" <[email protected]>
wrote
in
message
This is the code I've inserted:
Public Function GetFileNameFromFullPath
(PhotoLocation As
String) As String
GetFileNameFromFullPath = Right (PhotoLocation,
Len
(PhotoLocation) - InStrRev (PhotoLocation, "\", ,
vbTextCompare))
Me.PhotoName = GetFileNameFromFullPath
(PhotoLocation)
End Function

In the above, 'PhotoLocation' is the name of the
text
field that contains the full path; 'PhotoName' is
the
name
of the field that I want to show the trimmed file
name. I
don't know what I'm doing wrong.

-----Original Message-----
Hi,
Something like this:
Me.yourField = GetFileNameFromFullPath
("yourPath")

--
HTH
Dan Artuso, MVP


"Jimmy" <[email protected]>
wrote
in
message
Dan,
I found the problem. Typing errors. It is now
compiling. How do I call it and connect it to
the
text
field on my form?
-----Original Message-----
Hi,
Here's what I use:

Public Function GetFileNameFromFullPath
(fullPath
As
String) As String
GetFileNameFromFullPath = Right(fullPath, Len
(fullPath) -
InStrRev(fullPath,
"\", , vbTextCompare))
End Function

You may want to add some validation/error
handling.
HTH
Dan Artuso, MVP

"Jimmy G"
<[email protected]>
wrote
in
message
[email protected]...
Can anyone show me the proper use of
InStrRev
to
limit
the
full path name to just the filename?


.



.



.



.



.


.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top