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

how to pop-up the FILE OPEN dialog box ??? 1

Status
Not open for further replies.

marco02

Programmer
Feb 19, 2002
35
0
0
US
Hi,

I'm trying to pop up the FILE OPEN common dialog box for my user. The code below doesn't work! (comes from the "Developer's Handbook: Vol 1)

Dim cdl as CommonDlg
Set cdl = New CommonDlg
cdl.ShowOpen

Bugs at the first line. Declaration not accepted !! ...

thanks for your help on this matter,

marco
 
You may not have the CommonDialog control. It's included, I think, with developer versions of Access. Do you have a developer version?

You also need a reference set in the References dialog. The library is named something like Microsoft Common Dialog Control 6.0. Rick Sprague
 
Here is an API call to do it

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

Dave
ToeShot@Hotmail.com
Today Is Tomorrows Yesterday. So Why Wait
 
Marco,

To solove your problem (rather than provide alternatives!!!), you've not imported the CommonDlg class into you database. Do this and it will work.

Craig
 
IT WORKS !!!
sorry for the late answer guys i got sick ....

For the next guy, here is the complete detailed procedure:

1) In a Form (whatever form) Toolbox -> More control ->
put the "Microsoft Common Dialog Control 6.0" control
somewhere in the form.

2) Go in Access VB editor

3) Tools -> Reference -> check "Microsoft Common Dialog Control 6.0". Validate

4) Code as follow:

Dim commonDlg As New CommonDialog
commonDlg.ShowOpen

Thanks guys, marco.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top