2017-01-23 438 views
0

我收到一个ByRef参数类型不匹配。下面的代码(varFile specificaly)重点介绍了错误:ByRef参数类型不匹配 - 访问VB

Call InsertCMS_Reports_2ndSave(varFile) 

这里是我的形式:

选项比较数据库

'Private Sub Command0_Click() 
Private Sub cmdFileDialog_Click() 

'Requires reference to Microsoft Office 12.0 Object Library. 

    Dim fDialog As Office.FileDialog 
    Dim varFile As Variant 

    '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" 
    .InitialFileName = "C:\Users\ABCDEF\Desktop\CCCEEe CMS Reports" 

     'Clear out the current filters, and add our own. 

     .Filters.Clear 
     '.Filters.Add "Access Databases", "*.MDB; *.ACCDB" 
     .Filters.Add "Access Projects", "*.txt" 
     '.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 the list box. 
     For Each varFile In .SelectedItems 
      ' Me.FileList.AddItem varFile 
     Call InsertCMS_Reports_2ndSave(varFile) 
     Next 
     Else 
     MsgBox "You clicked Cancel in the file dialog box." 
     End If 
    End With 
End Sub 

模块代码:

Function InsertCMS_Reports_2ndSave(FileName As String) 
    'DoCmd.DeleteObject CopyOfCOMPRPT_CE, "CMS_Reports_2ndSave" 
    DoCmd.TransferText acImportFixed, "CMS_Reports_Import", _ 
    "CMS_Reports_Import", "C:\Users\A088982\Desktop\January CMS reports for Centene\FileName" 
    CurrentDb.Execute "UPDATE CopyOfCOMPRPT_CE SET FileName = 'HLTH_COMPRPT_1701011028174_h0062.txt' WHERE FileName is NULL", dbFailOnError 
End Function 
+1

那不是VB.NET代码; access-vba IsNot VB.NET。请修复这些标签(也许添加VB6,如果这是真的 - 标签上的字提供指导) – Plutonix

+0

@Plutonix修复,谢谢! – KKP

+0

'InsertCMS_Reports_2ndSave()'声明了什么参数? –

回答

0

的您收到此错误的原因是因为您已将尺寸为varFile作为变体,howe你的函数期望一个字符串。试试这个:

Function InsertCMS_Reports_2ndSave(FileName)