一个模块,
Dim OFD As FileDialog
这名在运行时提示:用户定义类型未定义
如何去除这个错误?
完整模块如下
Option Compare Database
Option Explicit
'打开文件框
'Program Files\Common Files\Microsoft Shared\OFFICE12\MSO.DLL
'OpenFile("所有文件|*.*")
Public Function OpenFile(Optional ByVal FileType As String = "") As String
Dim OFD As FileDialog
Dim TS() As String
Dim F As Long
Set OFD = Access.Application.FileDialog(msoFileDialogOpen)
With OFD
.AllowMultiSelect = False
If Len(FileType) > 0 Then
TS = Split(FileType, "|")
.Filters.Clear
For F = 0 To UBound(TS) Step 2
Call .Filters.Add(TS(F), TS(F + 1))
Next
End If
Call .Show
If .SelectedItems.Count > 0 Then
OpenFile = .SelectedItems.Item(1)
End If
End With
End Function
With Application.FileDialog(3) 'msoFileDialogFilePicker
.Title = "选择后台数据库"
.Filters.Clear
.Filters.Add "Access 数据库文件", "*.accdb;*.mdb;*.mde"
.Filters.Add "所有文件", "*.*"
If .Show = True Then
If LinkData(.SelectedItems(1), strPassword) Then
AutoLinkData = True
Else
'如果选择的文件无效,则重新打开文件选取对话框重新选择
MsgBox "文件无效,请重新选择。", vbInformation
' GoTo FilePickerDialog
End If
End If
End With