InStrRev

J

Jimmg G

I get the error message "Sub or function not defined"
-----Original Message-----
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


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


"Jimmy G" <[email protected]> wrote
in
message
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"
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"
wrote
in
message
[email protected]...
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?


.



.



.



.



.



.


.
 
J

Jimmy G

This function is posted in the form code. Is that the
proper place?
-----Original Message-----
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


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


"Jimmy G" <[email protected]> wrote
in
message
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"
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"
wrote
in
message
[email protected]...
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?


.



.



.



.



.



.


.
 
J

Jimmy G

Can you post your exact code so I can very that I don't
have any typo's?
-----Original Message-----
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


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


"Jimmy G" <[email protected]> wrote
in
message
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"
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"
wrote
in
message
[email protected]...
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?


.



.



.



.



.



.


.
 
D

dan artuso

Hi,
You have to move the function out of the form's code module and into a standard module.
That way you can test it from the Immediate window.
In your database window you should have a Modules tab. Create a new module
(DO NOT name it the same as the function) and place the function in it.

The exact function code is:

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

--
HTH
Dan Artuso, MVP


Jimmy G said:
Can you post your exact code so I can very that I don't
have any typo's?
-----Original Message-----
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


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


message
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)



message
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"
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"
wrote
in
message
[email protected]...
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?


.



.



.



.



.



.


.
 
J

Jimmy G

I tried that, same result. I think there is something
wrong with the IstStrRev statement.
-----Original Message-----
Hi,
You have to move the function out of the form's code
module and into a standard module.
That way you can test it from the Immediate window.
In your database window you should have a Modules tab. Create a new module
(DO NOT name it the same as the function) and place the function in it.

The exact function code is:

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

--
HTH
Dan Artuso, MVP


Can you post your exact code so I can very that I don't
have any typo's?
-----Original Message-----
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" <[email protected]> wrote
in
message
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


"Jimmy G" <[email protected]>
wrote
in
message
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)



message
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"
wrote
in
message
[email protected]...
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]...
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