Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to creating a file search button on form 1

Status
Not open for further replies.

omarrpa

IS-IT--Management
May 17, 2006
3
US
Hi,

I'm trying to create a button to do the following...

1. Browse to a file
2. Create a hyperlink to that file and store this link in a field on the current record?

Thank you in advance for your help!

- Omar
 
omarrpa,[ol]
[li]Browse for a file:[ul]
[li]If your using Access 2002 or newer look at the [tt]FileDialog[/tt] class (you may need to add a reference to the Microsoft Office x.x Object Library).[/li]
[li]If your using Access 2000 or older you will need to use an API, search for [tt]GetOpenFileName[/tt] in this forum.[/li][/ul][/li]
[li]Once you use one of the above you can convert the filename to a Hyperlink and store in your table.[/li][/ol]

Hope this helps,
CMP

(GMT-07:00) Mountain Time (US & Canada)
 
I'm sorry--I forgot to mention that I'm a beginner in vb programming. If you could please give me an example of the code I need to use.

Thanks again!

- Omar
 
I created a form connected to a table with a hyperlink field. I created a command button and an unbound listbox. The following specifies a specific path as seen next to Dir$.

Go to design view of the form. Click on the command button. Click on the property button. Click on the Event Tab. Click in the box next to OnClick. Click on the button with the three dots. Select Code Builder.
Copy: (Sub and End Sub statements are already there)
Private Sub Command0_Click()
Dim LoadFiles As String
Dim strFill As String
LoadFiles = Dir$("c:\excelforcourse\*.*")
Do While LoadFiles > ""
strFill = strFill & LoadFiles & ";"
LoadFiles = Dir$
Loop
Me![1stFiles].RowSource = strFill
End Sub

On the AfterUpdate of the listbox (see above directions to place code), I placed:
Private Sub Ctl1stFiles_AfterUpdate()
Dim holdname As String
holdname = "#c:\excelforcourse\" & Me![1stfiles] & "#"
Me![hype].Value = holdname
End Sub

Me![hype] is the name of the hyperlink field.
Me![1stFiles] is the name of the listbox.

Note you need the # # signs around the path name.

They can now save the selection and it'll also open the file if clicked on.
 
Very nice!!! Thank you so much for the example fneily! :p

- Omar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top