Solved

Common Dialog in Access 2000

Posted on 2001-09-16
4
443 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 49

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 49

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
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.

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now