我正在尝试从Access中的另一个子调用sub并继续获得"编译器错误ByRef参数不匹配。我知道它说我传递的变量与被调用子中指定的变量不匹配。这是我的代码。我将变量firstDayOfStartMonth和firstDayOfEndMonth定义为日期,并将它们传递给第二个proc deleteCurrentData(startDate As Date,endDate As Date)。
非常感谢任何帮助。
Sub loadDataFromExcel()
Dim monthName1, monthName2 As String
Dim startMonth, endMonth, curMonth As Integer
Dim thisMonday, rptStartDate, rptEndDate, firstDayOfStartMonth, firstDayOfEndMonth As Date
thisMonday = Date - Weekday(Date, vbMonday) + 1
rptStartDate = thisMonday - 14
rptEndDate = thisMonday - 10
firstDayOfStartMonth = DateSerial(Year(rptStartDate), Month(rptStartDate), 1)
firstDayOfEndMonth = DateSerial(Year(rptEndDate), Month(rptEndDate), 1)
Call deleteCurrentData(firstDayOfStartMonth, firstDayOfEndMonth)
End Sub
Private Sub deleteCurrentData(startDate As Date, endDate As Date)
答案 0 :(得分:3)
我将变量
firstDayOfStartMonth
和firstDayOfEndMonth
定义为日期
实际上,情况并非如此!
当您使用此声明时
Dim thisMonday, rptStartDate, rptEndDate, firstDayOfStartMonth, firstDayOfEndMonth As Date
仅firstDayOfEndMonth
类型为Date
,其他值为Variant
。请尝试使用此声明
Dim thisMonday As Date, rptStartDate As Date, rptEndDate As Date, firstDayOfStartMonth As Date, firstDayOfEndMonth As Date
这将解决问题。
P.S。与
相同Dim monthName1, monthName2 As String
和
Dim startMonth, endMonth, curMonth As Integer
将其更改为
Dim monthName1 As String, monthName2 As String
和
Dim startMonth, endMonth As Integer, curMonth As Integer
相应地