473,400 Members | 2,163 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,400 software developers and data experts.

Returning only the file name

I am trying to get only the filename in the [file] but it returns the path and filename. I am new at Access and need help. What should I do?

Private Sub File_Click()
Dim fileName As String
Dim result As Integer
With Application.FileDialog(msoFileDialogFilePicker)
.Title = "Choose file"
.Filters.Add "All", "*.pdf"
.FilterIndex = 2
.AllowMultiSelect = False
.InitialFileName = "c:\"
result = .Show
If (result <> 0) Then
fileName = Trim(.SelectedItems.Item(1))
Me![Name].SetFocus
Me![Name].Text = fileName
End If
End With
End Sub
May 19 '07 #1
5 16854
ADezii
8,834 Expert 8TB
I am trying to get only the filename in the [file] but it returns the path and filename. I am new at Access and need help. What should I do?

Private Sub File_Click()
Dim fileName As String
Dim result As Integer
With Application.FileDialog(msoFileDialogFilePicker)
.Title = "Choose file"
.Filters.Add "All", "*.pdf"
.FilterIndex = 2
.AllowMultiSelect = False
.InitialFileName = "c:\"
result = .Show
If (result <> 0) Then
fileName = Trim(.SelectedItems.Item(1))
Me![Name].SetFocus
Me![Name].Text = fileName
End If
End With
End Sub
Insert this Line of Code after fileName = Trim(.SelectedItems.Item(1))
Expand|Select|Wrap|Line Numbers
  1. strFileNameOnly = Right$(FileName, Len(FileName) - InStrRev(FileName, "\"))
'Replace Me![Name].Text = fileName with
Expand|Select|Wrap|Line Numbers
  1. Me![Name].Text = strFileNameOnly
May 19 '07 #2
Thank you for your response.
That worked, but when I put in Option Explicit at the top, the "strFileNameOnly =" got highlighted and the folowing error was shown:

Compile Error:
Variable not defined

Why?
May 19 '07 #3
ADezii
8,834 Expert 8TB
Thank you for your response.
That worked, but when I put in Option Explicit at the top, the "strFileNameOnly =" got highlighted and the folowing error was shown:

Compile Error:
Variable not defined

Why?
That's because you never Declared it in the Procedure:
Expand|Select|Wrap|Line Numbers
  1. Dim strFileNameOnly As String
May 19 '07 #4
That's because you never Declared it in the Procedure:
Expand|Select|Wrap|Line Numbers
  1. Dim strFileNameOnly As String

Thanks a lot for your help, everything is working as it should now : )
May 20 '07 #5
ADezii
8,834 Expert 8TB
Thanks a lot for your help, everything is working as it should now : )
Glad it all worked out.
May 20 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Mountain Man | last post by:
Hi, I'm having trouble with the foreach function. I'm using it twice inside a user defined function with two different arrays, and in the second instance it's returning the value of the first...
2
by: jeff | last post by:
I have a php file that contains a couple of arrays used for state/country pull-down lists. I have two global arrays and an accessor method for each. I have some simple logging methods, so I know a...
0
by: Bruce Zigenfous | last post by:
Hello, I am using an ASP that uses a third party active-x control to upload a file to a file server using the ADO Stream Object. It uses the FileSystemObject to create folders and files, which...
4
by: mchoya | last post by:
I'm so frustrated. I'm beginning school next week and I have been working on a simple program for several days now without being able to complete it. (Though I have brushed up on a lot of C++...
13
by: Matthias Kaeppler | last post by:
Hi, I was wondering why library implementors often make getter functions return strings by value (copies). For example, in boost::filesystem the leaf() function returns an std::string by value....
4
by: Earl T | last post by:
When I try to get the netscape version for version 7, I get the HttpBrowserCapabilities class returning the version as 5 and not 7. (see code and output below) CODE HttpBrowserCapabilities...
29
by: tnspc | last post by:
I'm writing code for a class where I've set up functions to load data from a file in the same directory as the PHP file (using the "file" method). Then, the goal is for the program to take the info...
9
by: Hank Stalica | last post by:
So I've made a linked list class. I have a function that initiates this class, opens a file, parses it, and then inserts nodes into this temporary class. What I would like to do is then have...
1
by: bsprogs | last post by:
I am currnetly programming a file hosting website in PHP and I am slowly integrating AJAX into the website. Here is my problem: The user uploads the file. The server processes the file and...
0
by: =?Utf-8?B?QnJ5YW4=?= | last post by:
Hello group. I've migrated from Win 2003 server to Win 2008 server. I've been banging my head agaist a wall for several days now trying to figure this out. I have the following script that will...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.