Solved

open file dialog box help.....

Posted on 1998-07-14
6
368 Views
Last Modified: 2008-02-01
I need to open an open file dialog box to select files from anywhere on the harddrive...i have a 2.0 code but the dll's changed in 95... i need this for an attached table db selection box with the path returned to my attach table code
0
Comment
Question by:jedimike
  • 3
  • 2
6 Comments
 
LVL 5

Expert Comment

by:tuvi
ID: 1976688
What you need are just the two functions "GetOpenFileName" and "GetSaveFileName" which open up a dialog to allow user to choose and save file in any folder.

Here is the excerpt from Win32 API:

The GetOpenFileName function creates an Open common dialog box that lets the user specify the drive, directory, and the name of a file or set of files to open.

BOOL GetOpenFileName(

    LPOPENFILENAME lpofn       // address of structure with initialization data
   );      
 

Parameters

lpofn

Pointer to an OPENFILENAME structure that contains information used to initialize the dialog box. When GetOpenFileName returns, this structure contains information about the user's file selection.

 

Return Values

If the user specifies a filename and clicks the OK button, the return value is nonzero. The buffer pointed to by the lpstrFile member of the OPENFILENAME structure contains the full path and filename specified by the user.
If the user cancels or closes the Open dialog box or an error occurs, the return value is zero. To get extended error information, call the CommDlgExtendedError function, which can return one of the following values:

CDERR_FINDRESFAILURE      CDERR_NOHINSTANCE
CDERR_INITIALIZATION      CDERR_NOHOOK
CDERR_LOCKRESFAILURE      CDERR_NOTEMPLATE
CDERR_LOADRESFAILURE      CDERR_STRUCTSIZE
CDERR_LOADSTRFAILURE      FNERR_BUFFERTOOSMALL
CDERR_MEMALLOCFAILURE      FNERR_INVALIDFILENAME
CDERR_MEMLOCKFAILURE      FNERR_SUBCLASSFAILURE

The GetSaveFileName function creates a Save common dialog box that lets the user specify the drive, directory, and name of a file to save.

BOOL GetSaveFileName(

    LPOPENFILENAME lpofn       // address of structure with initialization data
   );      
 

Parameters

lpofn

Pointer to an OPENFILENAME structure that contains information used to initialize the dialog box. When GetSaveFileName returns, this structure contains information about the user's file selection.

 

Return Values

If the user specifies a filename and clicks the OK button, the return value is nonzero. The buffer pointed to by the lpstrFile member of the OPENFILENAME structure contains the full path and filename specified by the user.
If the user cancels or closes the Save dialog box or an error occurs, the return value is zero. To get extended error information, call the CommDlgExtendedError function, which can return one of the following values:

CDERR_FINDRESFAILURE      CDERR_NOHINSTANCE
CDERR_INITIALIZATION      CDERR_NOHOOK
CDERR_LOCKRESFAILURE      CDERR_NOTEMPLATE
CDERR_LOADRESFAILURE      CDERR_STRUCTSIZE
CDERR_LOADSTRFAILURE      FNERR_BUFFERTOOSMALL
CDERR_MEMALLOCFAILURE      FNERR_INVALIDFILENAME
CDERR_MEMLOCKFAILURE      FNERR_SUBCLASSFAILURE

The OPENFILENAME structure contains information that the GetOpenFileName and GetSaveFileName functions use to initialize an Open or Save As common dialog box. After the user closes the dialog box, the system returns information about the user's selection in this structure.

typedef struct tagOFN { // ofn  
    DWORD         lStructSize;
    HWND          hwndOwner;
    HINSTANCE     hInstance;
    LPCTSTR       lpstrFilter;
    LPTSTR        lpstrCustomFilter;
    DWORD         nMaxCustFilter;
    DWORD         nFilterIndex;
    LPTSTR        lpstrFile;
    DWORD         nMaxFile;
    LPTSTR        lpstrFileTitle;
    DWORD         nMaxFileTitle;
    LPCTSTR       lpstrInitialDir;
    LPCTSTR       lpstrTitle;
    DWORD         Flags;

    WORD          nFileOffset;
    WORD          nFileExtension;
    LPCTSTR       lpstrDefExt;
    DWORD         lCustData;
    LPOFNHOOKPROC lpfnHook;
    LPCTSTR       lpTemplateName;
} OPENFILENAME;
 

Members

lStructSize

Specifies the length, in bytes, of the structure.

hwndOwner

Identifies the window that owns the dialog box. This member can be any valid window handle, or it can be NULL if the dialog box has no owner.

hInstance

If the OFN_ENABLETEMPLATEHANDLE flag is set in the Flags member, hInstance is the handle of a memory object containing a dialog box template. If the OFN_ENABLETEMPLATE flag is set, hInstance identifies a module that contains a dialog box template named by the lpTemplateName member. If neither flag is set, this member is ignored.

If the OFN_EXPLORER flag is set, the system uses the specified template to create a dialog box that is a child of the default Explorer-style dialog box. If the OFN_EXPLORER flag is not set, the system uses the template to create an old-style dialog box that replaces the default dialog box.

lpstrFilter

Pointer to a buffer containing pairs of null-terminated filter strings. The last string in the buffer must be terminated by two NULL characters.
The first string in each pair is a display string that describes the filter (for example, "Text Files"), and the second string specifies the filter pattern (for example, "*.TXT"). To specify multiple filter patterns for a single display string, use a semicolon to separate the patterns (for example, "*.TXT;*.DOC;*.BAK"). A pattern string can be a combination of valid filename characters and the asterisk (*) wildcard character. Do not include spaces in the pattern string.

The operating system does not change the order of the filters. It displays them in the File Types combo box in the order specified in lpstrFilter.
If lpstrFilter is NULL, the dialog box does not display any filters.

lpstrCustomFilter

Pointer to a static buffer that contains a pair of null-terminated filter strings for preserving the filter pattern chosen by the user. The first string is your display string that describes the custom filter, and the second string is the filter pattern selected by the user. The first time your application creates the dialog box, you specify the first string, which can be any nonempty string. When the user selects a file, the dialog box copies the current filter pattern to the second string. The preserved filter pattern can be one of the patterns specified in the lpstrFilter buffer, or it can be a filter pattern typed by the user. The system uses the strings to initialize the user-defined file filter the next time the dialog box is created. If the nFilterIndex member is zero, the dialog box uses the custom filter.

If this member is NULL, the dialog box does not preserve user-defined filter patterns.

If this member is not NULL, the value of the nMaxCustFilter member must specify the size, in bytes (ANSI version) or characters (Unicode version), of the lpstrCustomFilter buffer.

nMaxCustFilter

Specifies the size, in bytes or characters, of the buffer identified by lpstrCustomFilter. This buffer should be at least 40 characters long. This member is ignored if lpstrCustomFilter is NULL or points to a NULL string.

nFilterIndex

Specifies the index of the currently selected filter in the File Types control. The buffer pointed to by lpstrFilter contains pairs of strings that define the filters. The first pair of strings has an index value of 1, the second pair 2, and so on. An index of zero indicates the custom filter specified by lpstrCustomFilter. You can specify an index on input to indicate the initial filter description and filter pattern for the dialog box. When the user selects a file, nFilterIndex returns the index of the currently displayed filter.

If nFilterIndex is zero and lpstrCustomFilter is NULL, the system uses the first filter in the lpstrFilter buffer. If all three members are zero or NULL, the system does not use any filters and does not show any files in the file list control of the dialog box.

lpstrFile

Pointer to a buffer that contains a filename used to initialize the File Name edit control. The first character of this buffer must be NULL if initialization is not necessary. When the GetOpenFileName or GetSaveFileName function returns successfully, this buffer contains the drive designator, path, filename, and extension of the selected file.
If the OFN_ALLOWMULTISELECT flag is set and the user selects multiple files, the buffer contains the current directory followed by the filenames of the selected files. For Explorer-style dialog boxes, the directory and filename strings are NULL separated, with an extra NULL character after the last filename. For old-style dialog boxes, the strings are space separated and the function uses short filenames for filenames with spaces. You can use the FindFirstFile function to convert between long and short filenames.

If the buffer is too small, the function returns FALSE and the CommDlgExtendedError function returns FNERR_BUFFERTOOSMALL. In this case, the first two bytes of the lpstrFile buffer contain the required size, in bytes or characters.

nMaxFile

Specifies the size, in bytes (ANSI version) or characters (Unicode version), of the buffer pointed to by lpstrFile. The GetOpenFileName and GetSaveFileName functions return FALSE if the buffer is too small to contain the file information. The buffer should be at least 256 characters long.

lpstrFileTitle

Pointer to a buffer that receives the filename and extension (without path information) of the selected file. This member can be NULL.

nMaxFileTitle

Specifies the size, in bytes (ANSI version) or characters (Unicode version), of the buffer pointed to by lpstrFileTitle. This member is ignored if lpstrFileTitle is NULL.

lpstrInitialDir

Pointer to a string that specifies the initial file directory. If this member is NULL, the system uses the current directory as the initial directory.

lpstrTitle

Pointer to a string to be placed in the title bar of the dialog box. If this member is NULL, the system uses the default title (that is, "Save As" or "Open").

Flags

A set of bit flags you can use to initialize the dialog box. When the dialog box returns, it sets these flags to indicate the user's input. This member can be a combination of the following flags:

 

Flag      Meaning
OFN_ALLOWMULTISELECT      
Specifies that the File Name list box allows multiple selections. If you also set the OFN_EXPLORER flag, the dialog box uses the Explorer-style user interface; otherwise, it uses the old-style user interface. If the user selects more than one file, the lpstrFile buffer returns the path to the current directory followed by the filenames of the selected files. The nFileOffset member is the offset to the first filename, and the nFileExtension member is not used. For Explorer-style dialog boxes, the directory and filename strings are NULL separated, with an extra NULL character after the last filename. This format enables the Explorer-style dialogs to return long filenames that include spaces. For old-style dialog boxes, the directory and filename strings are separated by spaces and the function uses short filenames for filenames with spaces. You can use the FindFirstFile function to convert between long and short filenames. If you specify a custom template for an old-style dialog box, the definition of the File Name list box must contain the LBS_EXTENDEDSEL value.
 
 OFN_CREATEPROMPT      
If the user specifies a file that does not exist, this flag causes the dialog box to prompt the user for permission to create the file. If the user chooses to create the file, the dialog box closes and the function returns the specified name; otherwise, the dialog box remains open.
OFN_ENABLEHOOK      
Enables the hook function specified in the lpfnHook member.
OFN_ENABLETEMPLATE      
Indicates that the lpTemplateName member points to the name of a dialog template resource in the module identified by the hInstance member.If the OFN_EXPLORER flag is set, the system uses the specified template to create a dialog box that is a child of the default Explorer-style dialog box. If the OFN_EXPLORER flag is not set, the system uses the template to create an old-style dialog box that replaces the default dialog box.
OFN_ENABLETEMPLATEHANDLE      
Indicates that the hInstance member identifies a data block that contains a preloaded dialog box template. The system ignores the lpTemplateName if this flag is specified.If the OFN_EXPLORER flag is set, the system uses the specified template to create a dialog box that is a child of the default Explorer-style dialog box. If the OFN_EXPLORER flag is not set, the system uses the template to create an old-style dialog box that replaces the default dialog box.
OFN_EXPLORER      
Indicates that any customizations made to the Open or Save As dialog box use the new Explorer-style customization methods. For more information, see the "Explorer-Style Hook Procedures" and "Explorer-Style Custom Templates" sections of the Common Dialog Box Library overview.By default, the Open and Save As dialog boxes use the Explorer-style user interface regardless of whether this flag is set. This flag is necessary only if you provide a hook procedure or custom template, or set the OFN_ALLOWMULTISELECT flag. If you want the old-style user interface, omit the OFN_EXPLORER flag and provide a replacement old-style template or hook procedure. If you want the old style but do not need a custom template or hook procedure, simply provide a hook procedure that always returns FALSE.
OFN_EXTENSIONDIFFERENT      
Specifies that the user typed a filename extension that differs from the extension specified by lpstrDefExt. The function does not use this flag if lpstrDefExt is NULL.
OFN_FILEMUSTEXIST      
Specifies that the user can type only names of existing files in the File Name entry field. If this flag is specified and the user enters an invalid name, the dialog box procedure displays a warning in a message box. If this flag is specified, the OFN_PATHMUSTEXIST flag is also used.
OFN_HIDEREADONLY      
Hides the Read Only check box.
OFN_LONGNAMES      
For old-style dialog boxes, this flag causes the dialog box to use long filenames. If this flag is not specified, or if the OFN_ALLOWMULTISELECT flag is also set, old-style dialog boxes use short filenames (8.3 format) for filenames with spaces. Explorer-style dialog boxes ignore this flag and always display long filenames.
OFN_NOCHANGEDIR      
Restores the current directory to its original value if the user changed the directory while searching for files.
OFN_NODEREFERENCELINKS      
Directs the dialog box to return the path and filename of the selected shortcut (.LNK) file. If this value is not given, the dialog box returns the path and filename of the file referenced by the shortcut
OFN_NOLONGNAMES      
For old-style dialog boxes, this flag causes the dialog box to use short filenames (8.3 format). Explorer-style dialog boxes ignore this flag and always display long filenames.
OFN_NONETWORKBUTTON      
Hides and disables the Network button.
OFN_NOREADONLYRETURN      
Specifies that the returned file does not have the Read Only check box checked and is not in a write-protected directory.
OFN_NOTESTFILECREATE      
Specifies that the file is not created before the dialog box is closed. This flag should be specified if the application saves the file on a create-nonmodify network sharepoint. When an application specifies this flag, the library does not check for write protection, a full disk, an open drive door, or network protection. Applications using this flag must perform file operations carefully, because a file cannot be reopened once it is closed.
OFN_NOVALIDATE      
Specifies that the common dialog boxes allow invalid characters in the returned filename. Typically, the calling application uses a hook procedure that checks the filename by using the FILEOKSTRING message. If the text box in the edit control is empty or contains nothing but spaces, the lists of files and directories are updated. If the text box in the edit control contains anything else, nFileOffset and nFileExtension are set to values generated by parsing the text. No default extension is added to the text, nor is text copied to the buffer specified by lpstrFileTitle.
If the value specified by nFileOffset is less than zero, the filename is invalid. Otherwise, the filename is valid, and nFileExtension and nFileOffset can be used as if the OFN_NOVALIDATE flag had not been specified.
OFN_OVERWRITEPROMPT      
Causes the Save As dialog box to generate a message box if the selected file already exists. The user must confirm whether to overwrite the file.
OFN_PATHMUSTEXIST      
Specifies that the user can type only valid paths and filenames. If this flag is used and the user types an invalid path and filename in the File Name entry field, the dialog box function displays a warning in a message box.
OFN_READONLY      
Causes the Read Only check box to be checked initially when the dialog box is created. This flag indicates the state of the Read Only check box when the dialog box is closed.
OFN_SHAREAWARE      
Specifies that if a call to the OpenFile function fails because of a network sharing violation, the error is ignored and the dialog box returns the selected filename. If this flag is not set, the dialog box notifies your hook procedure when a network sharing violation occurs for the filename specified by the user. If you set the OFN_EXPLORER flag, the dialog box sends the CDN_SHAREVIOLATION message to the hook procedure. If you do not set OFN_EXPLORER, the dialog box sends the SHAREVISTRING registered message to the hook procedure.
OFN_SHOWHELP      
Causes the dialog box to display the Help button. The hwndOwner member must specify the window to receive the HELPMSGSTRING registered messages that the dialog box sends when the user clicks the Help button.An Explorer-style dialog box sends a CDN_HELP notification message to your hook procedure when the user clicks the Help button.
 

nFileOffset

Specifies a zero-based offset from the beginning of the path to the filename in the string pointed to by lpstrFile. For example, if lpstrFile points to the following string, "c:\dir1\dir2\file.ext", this member contains the value 13 to indicate the offset of the "file.ext" string.

nFileExtension

Specifies a zero-based offset from the beginning of the path to the filename extension in the string pointed to by lpstrFile. For example, if lpstrFile points to the following string, "c:\dir1\dir2\file.ext", this member contains the value 18. If the user did not type an extension and lpstrDefExt is NULL, this member specifies an offset to the terminating null character. If the user typed "." as the last character in the filename, this member specifies zero.

lpstrDefExt

Points to a buffer that contains the default extension. GetOpenFileName and GetSaveFileName append this extension to the filename if the user fails to type an extension. This string can be any length, but only the first three characters are appended. The string should not contain a period (.). If this member is NULL and the user fails to type an extension, no extension is appended.

lCustData

Specifies application-defined data that the system passes to the hook procedure identified by the lpfnHook member. When the system sends the WM_INITDIALOG message to the hook procedure, the message's lParam parameter is a pointer to the OPENFILENAME structure specified when the dialog box was created. The hook procedure can use this pointer to get the lCustData value.

lpfnHook

Pointer to a hook procedure. This member is ignored unless the Flags member includes the OFN_ENABLEHOOK flag.
If the OFN_EXPLORER flag is not set in the Flags member, lpfnHook is a pointer to an OFNHookProcOldStyle hook procedure that receives messages intended for the dialog box. The hook procedure returns FALSE to pass a message to the default dialog box procedure or TRUE to discard the message.
If OFN_EXPLORER is set, lpfnHook is a pointer to an OFNHookProc hook procedure. The hook procedure receives notification messages sent from the dialog box. The hook procedure also receives messages for any additional controls that you defined by specifying a child dialog template. The hook procedure does not receive messages intended for the standard controls of the default dialog box.

lpTemplateName

Pointer to a null-terminated string that names a dialog template resource in the module identified by the hInstance member. For numbered dialog box resources, this can be a value returned by the MAKEINTRESOURCE macro. This member is ignored unless the OFN_ENABLETEMPLATE flag is set in the Flags member.

If the OFN_EXPLORER flag is set, the system uses the specified template to create a dialog box that is a child of the default Explorer-style dialog box. If the OFN_EXPLORER flag is not set, the system uses the template to create an old-style dialog box that replaces the default dialog box.
----------------------------------------------
Here are the implementations in Access:

Public Const CDERR_DIALOGFAILURE = &HFFFF
Public Const CDERR_FINDRESFAILURE = &H6
Public Const CDERR_GENERALCODES = &H0
Public Const CDERR_INITIALIZATION = &H2
Public Const CDERR_LOADRESFAILURE = &H7
Public Const CDERR_LOADSTRFAILURE = &H5
Public Const CDERR_LOCKRESFAILURE = &H8
Public Const CDERR_MEMALLOCFAILURE = &H9
Public Const CDERR_MEMLOCKFAILURE = &HA
Public Const CDERR_NOHINSTANCE = &H4
Public Const CDERR_NOHOOK = &HB
Public Const CDERR_NOTEMPLATE = &H3
Public Const CDERR_REGISTERMSGFAIL = &HC
Public Const CDERR_STRUCTSIZE = &H1

Public Const OFN_ALLOWMULTISELECT = &H200
Public Const OFN_CREATEPROMPT = &H2000
Public Const OFN_ENABLEHOOK = &H20
Public Const OFN_ENABLETEMPLATE = &H40
Public Const OFN_ENABLETEMPLATEHANDLE = &H80
Public Const OFN_EXPLORER = &H80000                        
Public Const OFN_EXTENSIONDIFFERENT = &H400
Public Const OFN_FILEMUSTEXIST = &H1000
Public Const OFN_HIDEREADONLY = &H4
Public Const OFN_LONGNAMES = &H200000                      
Public Const OFN_NOCHANGEDIR = &H8
Public Const OFN_NODEREFERENCELINKS = &H100000
Public Const OFN_NOLONGNAMES = &H40000                      
Public Const OFN_NONETWORKBUTTON = &H20000
Public Const OFN_NOREADONLYRETURN = &H8000
Public Const OFN_NOTESTFILECREATE = &H10000
Public Const OFN_NOVALIDATE = &H100
Public Const OFN_OVERWRITEPROMPT = &H2
Public Const OFN_PATHMUSTEXIST = &H800
Public Const OFN_READONLY = &H1
Public Const OFN_SHAREAWARE = &H4000
Public Const OFN_SHAREFALLTHROUGH = 2
Public Const OFN_SHARENOWARN = 1
Public Const OFN_SHAREWARN = 0
Public Const OFN_SHOWHELP = &H10
Public Const OFS_MAXPATHNAME = 128

Type OPENFILENAME
    lStructSize As Long
    hwndOwner As Long                       // 0
    hInstance As Long                          // 0
    lpstrFilter As String
    lpstrCustomFilter As String             // 0
    nMaxCustFilter As Long                 // 0
    nFilterIndex As Long                      // 0
    lpstrFile As String
    nMaxFile As Long
    lpstrFileTitle As String                    // 0
    nMaxFileTitle As Long                    // 0
    lpstrInitialDir As String                    // 0
    lpstrTitle As String                         // 0
    flags As Long
    nFileOffset As Integer
    nFileExtension As Integer
    lpstrDefExt As String
    lCustData As Long                         // 0
    lpfnHook As Long                           // 0
    lpTemplateName As String              // 0
end Type

Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
Declare Function GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" (pOpenfilename As OPENFILENAME) As Long

The ones that I mark as //0 you can safely set them to 0 before use. Also remember that all the strings in Win32 API are c-string which is null-appended. In Access, you have to add the character Chr$(0) to the end on input and subtract that when retrieve.
0
 
LVL 2

Author Comment

by:jedimike
ID: 1976689
i need access95 code...and something clear for a layman to understand please..
0
 
LVL 5

Expert Comment

by:tuvi
ID: 1976690
But those are Access code. I include the excerpts to make you better understand. You need to include all those "Access implementation code" in your module before you can use it. There are only two functions:GetOpenFileName and GetSaveFileName which use a special type called OPENFILENAME. Before you use the functions, just fill in the structure type OPENFILENAME. Most of the defaults to zero, I already mark for you. The rest just fill in. (Read the documentation, it's not that hard really).
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 2

Author Comment

by:jedimike
ID: 1976691
somebody help me understand...I dont know any API programming...
0
 
LVL 9

Accepted Solution

by:
perove earned 70 total points
ID: 1976692
OK here it comes:

In a Module's Declare section add the following:
Type apitagOPENFILENAME
    nStructSize       As Long
    hwndOwner         As Long
    hInstance         As Long
    sFilter           As String
    sCustomFilter     As String
    nCustFilterSize   As Long
    nFilterIndex      As Long
    sFile             As String
    nFileSize         As Long
    sFileTitle        As String
    nTitleSize        As Long
    sInitDir          As String
    sDlgTitle         As String
    Flags             As Long
    nFileOffset       As Integer
    nFileExt          As Integer
    sDefFileExt       As String
    nCustDataSize     As Long
    fnHook            As Long
    sTemplateName     As String
End Type
Declare Function apiGetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (OPENFILENAME As apitagOPENFILENAME) As Long
'***********
Then create a public function in a moudule:
Function OpenFil32(Tittel As String, DefExt As String, Katalog As String, Filter As String) As String
  Dim OPENFILENAME As apitagOPENFILENAME
  Dim Message$, FileName$, FileTitle$, Title$, Msg$, CRLF$
  Dim szCurDir$, APIResults%

    CRLF$ = Chr$(13) & Chr$(10)

    '*Define the filter string and allocate space in the "c" string
    If Len(Filter) = 0 Then
        Filter = "Text(*.txt)" & Chr$(0) & "*.TXT" & Chr$(0)
        Filter = Filter & "Access(*.mdb)" & Chr$(0) & "*.MDB;*.MDA" & Chr$(0)
        Filter = Filter & "Batch(*.bat)" & Chr$(0) & "*.BAT" & Chr$(0)
        Filter = Filter & Chr$(0)
    ElseIf Right$(Filter, 1) <> Chr$(0) Then 'sjekk om det er null i enden av strengen
        Filter = Filter & Chr$(0)
    End If
    OPENFILENAME.sFilter = Filter
    '* Allocate string space for the returned strings.
    'FileName$ = Chr$(0) & Space$(255) & Chr$(0)
    FileName$ = Space$(255) & Chr$(0)
    OPENFILENAME.sFile = FileName$
    OPENFILENAME.nFileSize = Len(FileName$)
    FileTitle$ = Chr$(0) & Space$(255) & Chr$(0)
    OPENFILENAME.sFileTitle = FileTitle$
    OPENFILENAME.nTitleSize = Len(OPENFILENAME.sFileTitle)
   
    'Sette denne slik at filOpenformen ikke forsvinner bak applikasjonen
    OPENFILENAME.hwndOwner = Screen.ActiveForm.Hwnd
    '* Give the dialog a caption title.
    If Len(Tittel) = 0 Then
        Tittel = "Open fil" & Chr$(0)
    ElseIf Right$(Tittel, 1) <> Chr$(0) Then 'sjekk om det er null i enden av strengen
        Tittel = Tittel & Chr$(0)
    End If
    OPENFILENAME.sDlgTitle = Tittel
   
    '* If the user does not specify an extension, append TXT.
   
    If Len(DefExt) = 0 Then
        DefExt = "TXT" & Chr$(0)
    ElseIf Right$(DefExt, 1) <> Chr$(0) Then 'sjekk om det er null i enden av strengen
        DefExt = DefExt & Chr$(0)
    End If
   
    '* Set up the defualt directory
    If Len(Katalog) = 0 Then
        szCurDir$ = CurDir$ & Chr$(0)
    ElseIf Right$(Katalog, 1) <> Chr$(0) Then 'sjekk om det er null i enden av strengen
        szCurDir$ = Katalog & Chr$(0)
    End If
    OPENFILENAME.sInitDir = szCurDir

    '* Set up the data structure before you call the GetOpenFileName

    'OPENFILENAME.hwndOwner = Screen.ActiveForm.Hwnd
        '* which will in turn it uses to display the Open Dialog form.
    OPENFILENAME.nStructSize = Len(OPENFILENAME)
    APIResults% = apiGetOpenFileName(OPENFILENAME)
 
    If APIResults% <> 0 Then
       'OpenFil32 = Left$(FileName$, InStr(FileName$, Chr$(0)) - 1)
       OpenFil32 = OPENFILENAME.sFile
    Else
       OpenFil32 = ""
    End If
   
End Function
'***********
Then on the button that launch the dialogbox add this
ME.MyFieldWhereThePathShouldCome= OpenFil32("choosefile", "MDB", "C:", "")


This is the best I can do
perove
0
 
LVL 5

Expert Comment

by:tuvi
ID: 1976693
After I look around, here is what I found:
Access has several samples databases. One of them is Solutions.mdb
Now, in that database, in the module "modRefreshTableLinks", you should find the complete implementation of GetOpenFileName and GetSaveFileOpen. If you still don't understand, just copy the whole module to your database and use it. At least you know it is from Microsoft and it is workable.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

759 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

20 Experts available now in Live!

Get 1:1 Help Now