Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Common Dialog in Access 2000

Posted on 2001-09-16
4
Medium Priority
?
458 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 54

Accepted Solution

by:
Ryan Chong earned 200 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 54

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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Suggested Courses

824 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