access thread: Common Dialog boxes
Message #1 by "Paul Ansell" <paul.ansell@t...> on Wed, 17 Oct 2001 14:01:30
|
|
I want to somehow use a open/common dialog box to allow the user to browse
throught files on there machine and select a certain file. I then want to
be able to store the path and filename of that file in a field in the
database.
I've tried several things, but with no success as yet. Can anyone help me?
has anyone done anything like this before??
Thanks
Paul
Message #2 by "Guy Harwood" <guy@h...> on Wed, 17 Oct 2001 14:33:32
|
|
Use the following as you dont need to include an OCX when you distribute
the application (this uses an API instead)
The code ive shown you below will just generate a messagebox with the
path and target file. You would just substitute this for a variable then
save it to a table for your situation.
Hope this helps
Guy
##############
DEClarations section
##############
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
Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _
"GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
###############
BUTTON CLICK EVENT
###############
Private Sub cmdOpenDlg_Click()
Dim ofn As OPENFILENAME
ofn.lStructSize = Len(ofn)
ofn.hwndOwner = Me.hWnd
ofn.lpstrFilter = "(*.mdb)" + Chr$(0) + "*.mdb"
ofn.lpstrFile = Space$(254)
ofn.nMaxFile = 255
ofn.lpstrFileTitle = Space$(254)
ofn.nMaxFileTitle = 255
ofn.lpstrInitialDir = CurDir
ofn.lpstrTitle = "Dialog Title"
ofn.flags = 0
Dim a
a = GetOpenFileName(ofn)
If (a) Then
msgbox Trim$(ofn.lpstrFile)
Else
Exit Sub
End If
End Sub
Message #3 by Brian Skelton <brian.skelton@b...> on Wed, 17 Oct 2001 16:05:54 +0100
|
|
Paul
The code here: http://www.mvps.org/access/api/api0001.htm has some extra
functions for building filters to pass to the dialog box amongst other
things.
Brian
Message #4 by "Preethi" <preethi@s...> on Thu, 18 Oct 2001 08:56:36 +0600
|
|
I have done this in VB using Common Dialog Control. Hope that may work with
Access too.
|