Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to open the SaveAs Dialog Box

Status
Not open for further replies.

billdvldog

Programmer
Sep 6, 2001
43
I'm using the following from MS to open the OpenFile Common Dialog Box. I'd like to use the SaveAs Common Dialog Box as well, but I can't seem to find any info on how to do this. I'm sure it's a few simple modifications of the following, but I'm not sure how to do it. Any help is most definitely appreciated!

Thanks, Bill

<code>
Private Declare Function GetOpenFileName Lib &quot;comdlg32.dll&quot; Alias _
&quot;GetOpenFileNameA&quot; (pOpenfilename As OPENFILENAME) As Long

Private 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

Function LaunchCD(strform As Form, ByVal ImportName) As String

'This function opens the Common Open File Dialog Box, which allows the user to choose the appropriate filename
Dim OpenFile As OPENFILENAME
Dim lReturn As Long
Dim sFilter As String
OpenFile.lStructSize = Len(OpenFile)
OpenFile.hwndOwner = strform.Hwnd
sFilter = &quot;All Files (*.*)&quot; & Chr(0) & &quot;*.*&quot; & Chr(0)
OpenFile.lpstrFilter = sFilter
OpenFile.nFilterIndex = 1
OpenFile.lpstrFile = String(257, 0)
OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1
OpenFile.lpstrFileTitle = OpenFile.lpstrFile
OpenFile.nMaxFileTitle = OpenFile.nMaxFile
OpenFile.lpstrInitialDir = &quot;A:\&quot;
OpenFile.lpstrTitle = &quot;Select the &quot; + ImportName + &quot; Import File Name&quot;
OpenFile.flags = 0
lReturn = GetOpenFileName(OpenFile)
If lReturn = 0 Then
MsgBox &quot;A file was not selected!&quot;, vbInformation, _
&quot;Select a file using the Common Dialog DLL&quot;
Else
LaunchCD = Trim(OpenFile.lpstrFile)
End If
End Function
</code>
 
Christ!!! Hard work.......

How about using the Common Dialog Control itself rather than an API to it?

Much easier. The control can then be made to show a Save As dialog box by......

ControlName.ShowSave

Craig
 
Now there's an idea! Geez... If I could get my head screwed on straight! Thanks Craig.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top