How to specify default file name ? 
Author Message
 How to specify default file name ?

Hi, I use the following function to open / save a file.
How can I specify a default filename in the open / save dialogbox ?

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

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

Public Function GetFileName(StrTitle As String, I As Integer)
On Error GoTo err_GetFileName:
    Dim OpenFile As OPENFILENAME
    Dim lReturn As Long
    With OpenFile
        .lStructSize = Len(OpenFile)
        .lpstrFilter = "ProData A8 (*.MDB)" & Chr(0) & "*.MDB"
        .nFilterIndex = 1
        .lpstrFile = String(257, 0)
        .nMaxFile = Len(.lpstrFile) - 1
        .lpstrFileTitle = .lpstrFile
        .nMaxFileTitle = .nMaxFile
        .lpstrInitialDir = P_RootDir
        .lpstrTitle = StrTitle
        .flags = 0
        Select Case I
            Case 1
                lReturn = GetOpenFileName(OpenFile)
                MsgBox lReturn
                If lReturn <> 0 Then GetFileName = Trim(.lpstrFile)
            Case 2
                lReturn = GetSaveFileName(OpenFile)
                MsgBox lReturn
                If lReturn <> 0 Then GetFileName = Trim(.lpstrFile)
        End Select
    End With
exit_GetFileName:
    Exit Function
err_GetFileName:
    Err_Msg
    Resume exit_GetFileName:
End Function

Thanks for any help.



Mon, 19 Mar 2001 03:00:00 GMT  
 How to specify default file name ?
Change your declaration line to

Public Function GetFileName(StrTitle As String, I As Integer, Optional
strFileName As String = "")

and then change the following line
    .lpstrFile = String(257 , 0)

to
    .lpstrFile = strFileName & String(257 - Len(strFileName), 0)

Quote:

>Hi, I use the following function to open / save a file.
>How can I specify a default filename in the open / save dialogbox ?

>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

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

>Public Function GetFileName(StrTitle As String, I As Integer)
>On Error GoTo err_GetFileName:
>    Dim OpenFile As OPENFILENAME
>    Dim lReturn As Long
>    With OpenFile
>        .lStructSize = Len(OpenFile)
>        .lpstrFilter = "ProData A8 (*.MDB)" & Chr(0) & "*.MDB"
>        .nFilterIndex = 1
>        .lpstrFile = String(257, 0)
>        .nMaxFile = Len(.lpstrFile) - 1
>        .lpstrFileTitle = .lpstrFile
>        .nMaxFileTitle = .nMaxFile
>        .lpstrInitialDir = P_RootDir
>        .lpstrTitle = StrTitle
>        .flags = 0
>        Select Case I
>            Case 1
>                lReturn = GetOpenFileName(OpenFile)
>                MsgBox lReturn
>                If lReturn <> 0 Then GetFileName = Trim(.lpstrFile)
>            Case 2
>                lReturn = GetSaveFileName(OpenFile)
>                MsgBox lReturn
>                If lReturn <> 0 Then GetFileName = Trim(.lpstrFile)
>        End Select
>    End With
>exit_GetFileName:
>    Exit Function
>err_GetFileName:
>    Err_Msg
>    Resume exit_GetFileName:
>End Function

>Thanks for any help.



Mon, 19 Mar 2001 03:00:00 GMT  
 How to specify default file name ?
Thanks a lot Terry.
Do you happen to know how to manipulate the ComCtl32.DLL in order to avoid
the ComCtl32.OCX. I am currently using the TreeView and ProgressBar control.


Mon, 19 Mar 2001 03:00:00 GMT  
 How to specify default file name ?
Here are examples, on VB, i think you can make the same with Access:
http://members.aol.com/btmtz/vb/
http://www.zonecorp.com/VB5/

But i think not a good idea to program ComCtl32.DLL in Access. Better make
your own ActiveX control on VB with neccesary features and use it in Access.

Alex

Quote:

>Thanks a lot Terry.
>Do you happen to know how to manipulate the ComCtl32.DLL in order to avoid
>the ComCtl32.OCX. I am currently using the TreeView and ProgressBar
control.



Tue, 20 Mar 2001 03:00:00 GMT  
 How to specify default file name ?
Thanks a lot Alex.


Tue, 20 Mar 2001 03:00:00 GMT  
 How to specify default file name ?

Quote:
> Do you happen to know how to manipulate the ComCtl32.DLL in order to avoid
> the ComCtl32.OCX. I am currently using the TreeView and ProgressBar control.

You'd need to do a LOT of work to avoid this. You'd basically end up writing your own ActiveX
control to create the window, handle property settings, etc. Really, although I never use the
common dialog OCX (just easier to write the code directly), I wouldn't consider using the
common controls the same way. -- Ken


Tue, 20 Mar 2001 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. [ODC Driver Manager] Data source name not found and no default driver specified

2. Data Source Name not found and no default driver specified error

3. [ODBC Driver Manager] Data source name not found and no default driver specified

4. setting a printer to print to a file and specify a file name

5. Print to .prn file with specified name

6. Specifying a different name for a file download

7. How to specify name for email attachement file

8. specifying the report file name?

9. Saving a file with a default name.

10. Supplying Default File Name in Save window

11. show save as dialog with default doc path but current file name

12. Help setting default file names

 

 
Powered by phpBB® Forum Software