Hi paron,
Thanks for the reply! I remember this... Listed below is what I ended up doing... Hopefully this could help others as well...
Regards,
Jason
'-----------------------------------
' Code in my form
'-----------------------------------
Private Sub cmdCreate_Click()
Dim oDialog As Object, sDialogTitle As String, s_excelfile As String
Set oDialog = Me.xDialog.Object ' xDialog is the name of the ActiveX object (Microsoft Common Dialog Control) on the form
sDialogTitle = "Open..."
s_excelfile = GetFileName(oDialog, sDialogTitle, "Excel Spreadsheet (*.xls)", ".xls", 1)
If s_excelfile = "" Then
MsgBox "I cannot continue unless you provide the location and file name to Upload.", vbInformation, Me.Caption
Exit Sub
Else
... perform operations
End If
End Sub
'-----------------------------------
'--- Function below in a module ----
'-----------------------------------
Public Function GetFileName(oFrmDialog As Object, sTitle As String, sFilter As String, sText as String, iOp as Integer, Optional sName)
Dim s_File As String
s_File = ""
On Error GoTo Err_Browse
Dim strFilename As String
With oFrmDialog ' Ask for new file location.
.DialogTitle = sTitle
.Filter = sFilter
.FilterIndex = 1
.defaultext = sText
.cancelerror = True 'if cancel is pressed Err.Number = 32755
.InitDir = "c:\"
Select Case iOp
Case 1
.ShowOpen ' display Open dialog
Case 2
.filename = sName
.ShowSave ' display Save As dialog
End Select
If Len(.filename) > 0 Then ' user responded, put selection into text box on form.
s_File = .filename
End If
End With
GetFileName = s_File
Exit_Browse:
Exit Function
Err_Browse:
If Err.Number = 32755 Then
GetFileName = ""
Resume Exit_Browse
Else
MsgBox Err.DESCRIPTION
Resume Exit_Browse
End If
End Function