bosque
05-18-2011, 03:05 PM
Hi all. I'm relatively new to access, and I've had several issues getting my current database built. At this point everything is working well, except for the stupid file dialog box. I'm using Access 2007, FYI.
I found code online to open the dialog box and modified it to work with my tables. My problem is I get a runtime error that says user defined type is not defined. The error fires on my "Dim fDialog as Office.FileDialog" line. The specific error is "Compile error: User-defined type not defined". What am I doing wrong? I see the line in the code that says "' Requires reference to Microsoft Office 11.0 Object Library." Am I supposed to manually add a reference to some library somewhere in my code??
My code is here below:
Private Sub btn_retina_import_Click()
' Requires reference to Microsoft Office 11.0 Object Library.
Dim fDialog As Office.FileDialog
Dim varFile As Variant
lblStat.Caption = "Importing Retina Data"
' Clear listbox contents.
Me.Filelist.RowSource = ""
' Set up the File Dialog.
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
With fDialog
' Allow user to make multiple selections in dialog box
.AllowMultiSelect = True
' Set the title of the dialog box.
.Title = "Please select one or more files"
' Clear out the current filters, and add our own.
.Filters.Clear
.Filters.Add "Retina XML Data", "*.XML"
.Filters.Add "All Files", "*.*"
' Show the dialog box. If the .Show method returns True, the
' user picked at least one file. If the .Show method returns
' False, the user clicked Cancel.
If .Show = True Then
'Loop through each file selected and add it to our list box.
For Each varFile In .SelectedItems
Me.Filelist.AddItem varFile
Next
Else
MsgBox "You clicked Cancel in the file dialog box."
lblStat.Caption = "Idle"
Exit Sub
End If
End With
'Call up the XML Parser
i = Filelist.ListCount
i = i - 1
Do Until i = -1
X = Parse_Retina(Filelist.ItemData(i)) 'Call input method
i = i - 1
Loop
lblStat.Caption = "Idle"
I found code online to open the dialog box and modified it to work with my tables. My problem is I get a runtime error that says user defined type is not defined. The error fires on my "Dim fDialog as Office.FileDialog" line. The specific error is "Compile error: User-defined type not defined". What am I doing wrong? I see the line in the code that says "' Requires reference to Microsoft Office 11.0 Object Library." Am I supposed to manually add a reference to some library somewhere in my code??
My code is here below:
Private Sub btn_retina_import_Click()
' Requires reference to Microsoft Office 11.0 Object Library.
Dim fDialog As Office.FileDialog
Dim varFile As Variant
lblStat.Caption = "Importing Retina Data"
' Clear listbox contents.
Me.Filelist.RowSource = ""
' Set up the File Dialog.
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
With fDialog
' Allow user to make multiple selections in dialog box
.AllowMultiSelect = True
' Set the title of the dialog box.
.Title = "Please select one or more files"
' Clear out the current filters, and add our own.
.Filters.Clear
.Filters.Add "Retina XML Data", "*.XML"
.Filters.Add "All Files", "*.*"
' Show the dialog box. If the .Show method returns True, the
' user picked at least one file. If the .Show method returns
' False, the user clicked Cancel.
If .Show = True Then
'Loop through each file selected and add it to our list box.
For Each varFile In .SelectedItems
Me.Filelist.AddItem varFile
Next
Else
MsgBox "You clicked Cancel in the file dialog box."
lblStat.Caption = "Idle"
Exit Sub
End If
End With
'Call up the XML Parser
i = Filelist.ListCount
i = i - 1
Do Until i = -1
X = Parse_Retina(Filelist.ItemData(i)) 'Call input method
i = i - 1
Loop
lblStat.Caption = "Idle"