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

Browse Dialog 1

Status
Not open for further replies.

twsjd

Technical User
Sep 18, 2002
5
US
on a form i have a browse button. I used the code that everybody has been refered to on this site.


Is their anyway to modify it so that it only returns the filename not the full path?
 
OK I have to add two cents to this. I have seen these sites and the code looks very long for what is trying to be done. I have used the code below and it works every time

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 = "All Files *.*" & Chr(0) & "*.*" & 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



Dave
ToeShot@Hotmail.com
Today Is Tomorrows Yesterday. So Why Wait
 
I can't take credit for this I got it from a book and made just a couple of small mods like the filter and the file Lentghs. For some reason the original lengths caused errors.
The book

Access 2000 Power Programming
F. Scott Baker

Dave
ToeShot@Hotmail.com
Today Is Tomorrows Yesterday. So Why Wait
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top