Add browse feature

  • Thread starter Thread starter BDS
  • Start date Start date
B

BDS

Guest
Is there a way to add a browse feature to a form? For example, I need the ability for those using the Access form to be able to browse for a particular document and be able to add it to the Access database. Any help would be appreciated!
 
I got this bit of code from the Relink on startup module that is found in the soutions database and can also be found in the knowledge base.

Public Function Browse()
On Error GoTo Err_Browse

Dim strFilename As String
Dim oDialog As Object
Set oDialog = [Forms]![frmNewDataFile]!xDialog.Object

With oDialog
.DialogTitle = "Please select a new data file"
.Filter = "Access Database(*.mdb;*.mda;*.mde;*.mdw)|" & _
"*.mdb; *.mda; *.mde; *.mdw|All(*.*)|*.*"
.FilterIndex = 1
.ShowOpen
If Len(.FileName) > 0 Then
[Forms]![frmNewDataFile]![txtFileName] = .FileName
End If
End With

Exit_Browse:
Exit Function

Err_Browse:
MsgBox Err.Description
Resume Exit_Browse

End Function


This code works with the common dialog control that is described in the knowledge base.

Hope this is what you were wanting

Rachael
 
This is the code I've used. There is a command button on the form called cmdBrowse and a textbox called txtPath. Enter this code under the onclick event of cmdBrowse.

Private Sub cmdBrowse_Click()
Dim lpIDList As Long
Dim sBuffer As String
Dim szTitle As String
Dim tBrowseInfo As BROWSEINFO
szTitle = "Search in:-"
With tBrowseInfo
.hWndOwner = Me.hwnd
.lpszTitle = lstrcat(szTitle, "")
.ulFlags = BIF_RETURNONLYFSDIRS + BIF_DONTGOBELOWDOMAIN
End With
lpIDList = SHBrowseForFolder(tBrowseInfo)
If (lpIDList) Then
sBuffer = Space(MAX_PATH)
SHGetPathFromIDList lpIDList, sBuffer
sBuffer = Left(sBuffer, InStr(sBuffer, vbNullChar) - 1)
txtPath = sBuffer
txtPath.SetFocus
End If
End Sub

You then need to add the following code to a module that I've called basBrowse.

Option Compare Database

Public Const BIF_RETURNONLYFSDIRS = 1
Public Const BIF_DONTGOBELOWDOMAIN = 2
Public Const MAX_PATH = 260
Declare Function SHBrowseForFolder Lib _
"shell32" (lpBI As BROWSEINFO) As Long
Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList _
As Long, ByVal lpBuffer As String) As Long
Declare Function lstrcat Lib "kernel32" _
Alias "lstrcatA" (ByVal lpString1 As String, ByVal _
lpString2 As String) As Long
Public Type BROWSEINFO
hWndOwner As Long
pidlRoot As Long
pszDisplayName As Long
lpszTitle As Long
ulFlags As Long
lpfnCallback As Long
lParam As Long
iImage As Long
End Type

This should work, if not let me know

Dave
 

Users who are viewing this thread

Back
Top Bottom