在ACCESS vba中使用datevariables调用另一个子文件
我试图从Access中的另一个子调用一个子,并继续得到一个“编译器错误ByRef参数不匹配。我明白,它说,我传递的variables与被调用的sub中指定的不匹配,这是我的代码。我有variablesfirstDayOfStartMonth和firstDayOfEndMonth定义为date,并将它们传递给第二个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)
我有variables
firstDayOfStartMonth
和firstDayOfEndMonth
定义为date
事实上,这不是真的!
当你使用这个声明
Dim thisMonday, rptStartDate, rptEndDate, firstDayOfStartMonth, firstDayOfEndMonth As Date
只有firstDayOfEndMonth
是Date
types,其他值是Variant
。 尝试使用这个声明来代替
Dim thisMonday As Date, rptStartDate As Date, rptEndDate As Date, firstDayOfStartMonth As Date, firstDayOfEndMonth As Date
这将解决这个问题。
PS同样的事情
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
于是