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

Access common dialog

Status
Not open for further replies.

azrobert

Programmer
Apr 27, 2002
393
US
I am an amature access user and would like to browse for and copy files from one location to another. I have gotted a lot of help here, specifically from Neil Berryman, he had some great code for browsing files. My question is: does access support the common dialog control and if so I seem to need some help in registering it and what version to use. I am using access 2000.

thanks a lot !
 
The answer to your question is yes you can use the common dialog box control in access. The code is virtually the same as if you were programming in Visual basic 6.0 the only difference is when you type cmnDialog. you will not get a decent list of proporties of what the dialog does.

1) To add the dialog box to the form on your toolbox press the icon "more controls" then browse down to "Microsoft common dialog box, version 6.0" and then draw it on the form.

2) Add the code

To open the dialog box you use .showopen
The file that was choosen is .filename you can also try .FileTitle

You can set the default directory using .InitDir

You can also set filters as follows using .FilterIndex

"Executables (*.exe;*.com)|*.exe;*.com|All files (*.*)|*.*"

The are hundreds of methods to copy files you have to decide what is the best one for you there is also an API that i use when saving files to a Directory it works as follows:

Paste this into a module

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 = ""
End If
End Function

Then to call the directory selector use:

BrowseFolder("Copy files to")

"Copy files to" is the heading.

Hope this helps a little.

Jamie Mack
 
that is a start... will have to study... I get a error message "controll not registered" when i try to draw the com dialog controll........ I have tried re-registering it from the resources... i might have adifferent .ocx file on my system... will have to look at it more closely

thanks !
 
controll not registered when you get this it usually means that it is not registered in the registary.

This is what you need to run (i recommend making a batch file):

regsvr32 /s "C:\WINDOWS\SYSTEM\MSCAL.OCX"

Replace "MSCAL" with the file name of the common dialog box.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top