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

File Selection 1

Status
Not open for further replies.

ianbar

Technical User
Jan 10, 2003
69
GB
I have a parameters table (which holds the paths of several folders on a server). I have added text boxes to the form and I can edit the folder paths. I would like a user to be able to click a button and launch a save/save as style wizard that the user could use to find the folder and then the database inserts path in the text box. Can this be done?
 
Here is some VBA code to be pasted into a database module:
'************** Code Start **************
'This code was originally written by Terry Kreft.
'It is not to be altered or distributed,
'except as part of an application.
'You are free to use it in any application,
'provided the copyright notice is left unchanged.
'
'Code courtesy of
'Terry Kreft

Private Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type

Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias _
"SHGetPathFromIDListA" (ByVal pidl As Long, _
ByVal pszPath As String) As Long

Private Declare Function SHBrowseForFolder Lib "shell32.dll" Alias _
"SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) _
As Long

Private Const BIF_RETURNONLYFSDIRS = &H1
Public Function BrowseFolder(szDialogTitle As String) As String
Dim x As Long, bi As BROWSEINFO, dwIList As Long
Dim szPath As String, wPos As Integer

With bi
.hOwner = hWndAccessApp
.lpszTitle = szDialogTitle
.ulFlags = BIF_RETURNONLYFSDIRS
End With

dwIList = SHBrowseForFolder(bi)
szPath = Space$(512)
x = SHGetPathFromIDList(ByVal dwIList, ByVal szPath)

If x Then
wPos = InStr(szPath, Chr(0))
BrowseFolder = Left$(szPath, wPos - 1)
Else
BrowseFolder = vbNullString
End If
End Function
'*********** Code End *****************

Now to call this Function to allow the user to select a folder path:

Me.<YourControlName> = BrowseFolder(&quot;Find Path to folder&quot;)

Let me know if this helps you out.


Bob Scriver

Nobody believes the official spokesman... but everybody trusts an unidentified source.
Author, Bagdad Bob???

 
I get an error:

'Compile Error:

Expected Variable Proceedure, not module.'

I have this code behind the on_click action of a button:

Me!OFT_Temp_Folder = BrowseFolder(&quot;Find Path to folder&quot;)


 
No you put it in the wrong place. Copy the code from the green lines Code Start to Code End and paste this in a new database level module, not in the form itself.

This Function will now be able to be called from anywhere in your database.

The additional line of code I provided is what will make the call and allow the user to path to the folder they want.

Get back with me if there are more problems.

Bob Scriver

Nobody believes the official spokesman... but everybody trusts an unidentified source.
Author, Bagdad Bob???

 
That's what I did. I called the module BrowseFolder. With the code I put up behind a button to call the module.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top