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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannot use FILEDIALOG

Status
Not open for further replies.

jancheta

Programmer
Aug 30, 2002
51
0
0
US
Hi!
I'm trying to use the FileDialog object. In my References I have "Microsoft Access 10.0 Object Library" checked.

Part of my code is:
Dim fd as FileDialog

When I compile, I get a Compile error: User-defined type not defined for the code above.

Thanks in advance!

jason
 
While it is far too late to help jason, if anyone else finds this in a keyword search, I believe that "Dim fd as FileDialog" should be "Dim fd as Application.FileDialog"

 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top