common dialog box

  • Thread starter Thread starter Lotje
  • Start date Start date
L

Lotje

Guest
Hi there

how was it again that you can connect a common dialog box with a button just like 'File - Open'???

I need the path and the name then that the user clicked and then use the data in that file. How can I do this again in the code because it has been a while and I don't have my notes with me...

Greetz
 
Here you go...

Option Compare Database
'Open a Common Dialog box to export file too
Private Declare Function apiGetSaveFileName Lib "comdlg32.dll" _
Alias "GetSaveFileNameA" (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) As String
Dim OpenFile As OPENFILENAME
Dim lReturn As Long
Dim sFilter As String
OpenFile.lStructSize = Len(OpenFile)
OpenFile.hwndOwner = strform.Hwnd
sFilter = "Text Document (*.txt*)" & 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 = "C:\"
OpenFile.lpstrTitle = "Select a file for import"
OpenFile.flags = 0
lReturn = apiGetSaveFileName(OpenFile)
If lReturn = 0 Then
MsgBox "A file was not selected!", vbInformation, _
"Select a file"
Else
LaunchCD = Trim(OpenFile.lpstrFile)
End If
End Function



Private Sub cmdSusp_Click()
On Error GoTo Err_cmd_Click

Me.SuspendHL = LaunchCD(Me)

Exit_Close_Click:
Exit Sub

Err_cmd_Click:
MsgBox Err.Description
Resume Exit_Close_Click

End Sub



Whew....lots of typing....ctl+c....ctl+v....

:D
 

Users who are viewing this thread

Back
Top Bottom