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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select "File Path"

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I am trying to create a form which includes a control button. When the user clicks on the button, I would like the contents of the hard drive to open, allowing the user to browse to and select a file. The filename and/or path I would then like added to a text field. Has anyone seen this or know how to do it? What should I be doing? Thanks in advance... John
 
Read Access help file on hyperlink properties for tables. It will explain how use the Data Type: Hyperlink, as a method to link to folders via the information specified in the hyperlink field. I use it to open up folders created by my db that store documents created by my db. Its very handy.
 
Sure, a hyperlink would probably open the file, but not allow you to browse, select a file, and have the results return. That is exactly what the Common Dialog control does. Merely find and set the 'Commmon Dialog Control' (sic) as a reference or browse to Comdlg32.dll to add it as a reference and then add the handling code. Probably in the help file.



----------------------
scking@arinc.com
Life is filled with lessons.
We are responsible for the
results of the quizzes.
-----------------------
 
It's the same control that Windows Explorer uses.
----------------------
scking@arinc.com
Life is filled with lessons.
We are responsible for the
results of the quizzes.
-----------------------
 
Hi :)

I am sending you the standard module used for open dialog box. Copy the module in a new module called APIOpenFile

Option Compare Database


Option Explicit

Private Declare Function ap_GetOpenFileName Lib "comdlg32.dll" Alias _
"GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long

Private Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type

Public Function ap_FileOpen(Optional strTitle As String = "Open File", _
Optional strFileName As String = "", _
Optional strFilter As String = "") As String

Dim OpenFile As OPENFILENAME
Dim lngReturn As Long

If Len(strFileName) = 0 Then
strFileName = String(255, 0)
End If

If Len(strFilter) = 0 Then
strFilter = "Access Databases (*.mdb)" & Chr(0) & _
"*.mdb" & Chr(0)
End If

OpenFile.lStructSize = Len(OpenFile)

OpenFile.lpstrFilter = strFilter
OpenFile.nFilterIndex = 1
OpenFile.lpstrFile = strFileName + _
Space(255 - Len(strFileName))
OpenFile.nMaxFile = 255
OpenFile.lpstrFileTitle = strFileName
OpenFile.nMaxFileTitle = OpenFile.nMaxFile
OpenFile.lpstrInitialDir = CurrentProject.Path
OpenFile.lpstrTitle = strTitle
OpenFile.flags = 0

ap_GetOpenFileName OpenFile

ap_FileOpen = Left(OpenFile.lpstrFile, _
InStr(OpenFile.lpstrFile, Chr$(0)) - 1)

End Function
----------------------------------------

In your form write this behind your commad button to open the Open File Dialog box

Me.TxtDir = APIOpenFile.ap_FileOpen("Locate SearchCodes_Data.mdb")

Where TxtDir is the name of text box where the path of file will be stored.

Cheers!
Aqif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top