473,394 Members | 1,932 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,394 software developers and data experts.

Automatically Hyperlink when given part of the file name

Okay so i have been searching for a way to find a file given part of its file path, such as
("\\Qes1\data\Initial Data\C005900*.pdf"
and if that file exist grab the full file path an create a hyperlink to the file
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdPopulateHyperlink_Click()
  2. 'First, set a Reference to the Microsoft Office XX.X Object Library
  3.  
  4. 'Dim strButtonCaption As String, strDialogTitle As String
  5. Dim strHyperlinkFile As String
  6.  
  7. 'Define your own Captions if necessary
  8. strButtonCaption = "Save Hyperlink"
  9. strDialogTitle = "Select File to Create Hyperlink to"
  10.  
  11. With Application.FileDialog(msoFileDialogFilePicker)
  12.   With .Filters
  13.     .Clear
  14.     .Add ".PNG Files", "*.*"     'Allow only *.png File types
  15.   End With
  16.   'The Show Method returns True if 1 or more files are selected
  17.     .AllowMultiSelect = False       'Critical Line
  18.     .FilterIndex = 1 'Database files
  19.     .ButtonName = strButtonCaption
  20.     .InitialFileName = "\\Qes1\data\Initial Data\C005900*.*"
  21.     .InitialView = msoFileDialogViewDetails     'Detailed View
  22.    .Title = strDialogTitle
  23.   If .Show Then
  24.     For Each varItem In .SelectedItems 'There will only be 1
  25.       'Extract Caption and and add Address of Hyperlink (Caption#Address)
  26.       strHyperlinkFile = Mid$(varItem, InStrRev(varItem, "\") + 1) & "#" & varItem
  27.         Me![Link] = strHyperlinkFile
  28.     Next varItem
  29.   End If
  30. End With
  31.  
  32. End Sub
  33.  
Similar to this code but i don't want to have the pick the file. I want it to automatically grab the file.

All of the files are unique based on the CXXXXXX. Is there anyway to do this?

Edit: I am using access 2010
Apr 4 '14 #1

✓ answered by jimatqsi

cenaror,
Look at the Dir() command. A typical Dir() usage looks like this:
Expand|Select|Wrap|Line Numbers
  1. dim fname as string
  2. dim fpath as string
  3. dim ftemplate as string
  4.  
  5. fpath = "\\Qes1\data\Initial Data"
  6. ftemplate = me.template_txt ' text box with model file name
  7.  
  8. fname = Dir(fpath) ' find first file in the folder
  9. do while fname <> ""   ' until end of file names
  10.  ' do necessary file name comparisons here
  11.  ' and act on each file
  12. Dir() ' get next file name in the folder
  13. loop
It's possible to include sub-folders or ignore them.

Jim

2 2487
jimatqsi
1,271 Expert 1GB
cenaror,
Look at the Dir() command. A typical Dir() usage looks like this:
Expand|Select|Wrap|Line Numbers
  1. dim fname as string
  2. dim fpath as string
  3. dim ftemplate as string
  4.  
  5. fpath = "\\Qes1\data\Initial Data"
  6. ftemplate = me.template_txt ' text box with model file name
  7.  
  8. fname = Dir(fpath) ' find first file in the folder
  9. do while fname <> ""   ' until end of file names
  10.  ' do necessary file name comparisons here
  11.  ' and act on each file
  12. Dir() ' get next file name in the folder
  13. loop
It's possible to include sub-folders or ignore them.

Jim
Apr 5 '14 #2
Thank you,

I was able to figure it out using the Dir() command
Apr 7 '14 #3

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

Similar topics

0
by: Henke | last post by:
Hi! I populate a listBox with filenames. When a user dubbelclicks a filename in the list box I'd like to open the correct application that is associated to that filetype. Let's say a user clicks...
2
by: Chuck | last post by:
Using a macro to output a query to an Excel file. Is there a way to automatically add todays date in the file spec? As: C:\Access Data\ & todays date.xls Chuck ....
0
by: ChadDiesel | last post by:
Hello Everyone, I have a field set up in a table that is an OLE object with a link to an external Excel spreadsheet. My question is whether you can use a file path that contains wildcards. ...
5
by: Martha | last post by:
When I move my mouse over a hyperlink component, the hyperlink does not change color. How do I change the color of a hyperlink when the mouse goes over the hyperlink? or Change the color of a...
8
by: Sohan Kamat | last post by:
Hi, I have a webform and I want to create a hyperlink to a text file, so that it opens on internet explorer in a new window. I have added the following <a href="file:///D:/Test/Test.txt" ...
2
by: Shehab Kamal | last post by:
I'm using ASP.NET 1.1. I have a DataGrid in which I have a hyperlink column. The NavigateUrl of the hyperlink is an ftp file on the form "ftp://IP Address/fileName". When I click the hyperlink the...
4
by: kevin | last post by:
Hi, I am trying to create a page so the user can browse the network, select a file and have that file name (text) inserted into our sql DB so I can build the hyperlink path later on. Here's what...
9
by: Morris Neuman | last post by:
Im working with VS 2005 and trying to use a Hyperlink field in a datagrid to play a wave file that is not located in the website folders but is in a plain folder on the same machine, windows 2003...
185
by: jacob navia | last post by:
Hi We are rewriting the libc for the 64 bit version of lcc-win and we have added a new field in the FILE structure: char *FileName; fopen() will save the file name and an accessor function will...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.