Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Common Dialog in Access 2000

Posted on 2001-09-16
4
447 Views
Last Modified: 2008-02-01
I need to be able to browse for a file and insert that path into something. Is there something other than the common dialog control I can use? If not, (1) is the common dialog control on every system and (2) show me code to do this?
0
Comment
Question by:Misledman
  • 2
4 Comments
 
LVL 12

Expert Comment

by:Paurths
ID: 6486137
hi Misledman,

the common dialog component does not always work when u distribute your application to another computer.
If u use API however, it will always work since it is part of windows itself.
Here u will find an example of that :
http://www.mvps.org/access/api/api0001.htm

cheers
Ricky
0
 
LVL 50

Accepted Solution

by:
Ryan Chong earned 50 total points
ID: 6486470
Hi Misleadman,

Some other easy way to do this is using the COMDLG32.OCX ("Microsoft Common Dialog Control 6.0"):

In Access (Go to Module):

ACCESS Menu -> References -> Check "Microsoft Common Dialog Control 6.0"

IF Check "Microsoft Common Dialog Control 6.0" DOES NOT APPEAR..

Hit the Browse Button -> Navigate to x:\Windows\System -> find (or type in) COMDLG32.OCX -> Click
on Ok.

Then add the code like this:

'CD is the Common Dialog Control's name

CD.Flags = 4
CD.Filter = "Excel Files (*.xls)|*.xls"
CD.Open
If CD.FileName <> "" Then
      'A file is selected
      '...
End If

'You need to copy the COMDLG32.OCX and register it if your system don't get this file.

'Hope will help little.

0
 
LVL 2

Expert Comment

by:nschulz777
ID: 6504838
Post your email and Ill send you a sample mdb which uses windows API calls to browse for files. It avoids the headaches of some machines not having registered controls.
0
 
LVL 50

Expert Comment

by:Ryan Chong
ID: 6504868
Hi Misledman,

Here is another sample that enable a user to launch whether Save or Open dialog:

Public 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 Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
Public Declare Function GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" (pOpenfilename As OPENFILENAME) As Long

Public Function OpenDialogBox(ByVal frm As Form, ByVal filter As String, ByVal title As String, ByVal OpenSave As Byte) As String
    Dim ofn As OPENFILENAME
    ofn.lStructSize = Len(ofn)
    ofn.hwndOwner = frm.hwnd
    ofn.hInstance = App.hInstance
    ofn.lpstrFilter = filter
    ofn.nFilterIndex = 1
    ofn.lpstrFile = Space$(254)
    ofn.nMaxFile = 255
    ofn.lpstrFileTitle = Space$(254)
    ofn.nMaxFileTitle = 255
    ofn.lpstrInitialDir = CurDir
    ofn.lpstrTitle = title
    ofn.flags = 6
    Dim OpenDialog As Long
    If OpenSave = 1 Then
        OpenDialog = GetOpenFileName(ofn)
        If (OpenDialog) Then
            If Dir$(Trim$(ofn.lpstrFile)) <> "" Then
                OpenDialogBox = Trim$(ofn.lpstrFile)
            End If
        Else
            OpenDialogBox = "" 'Cancel was pressed
        End If
    Else ' = 2
        OpenDialog = GetSaveFileName(ofn)
        If OpenDialog > 0 Then
            OpenDialogBox = Trim$(ofn.lpstrFile)
        Else
            OpenDialogBox = ""
        End If
    End If
End Function

'Hope will help.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question