Calling a sub from another using date variables in ACCESS vba

I am trying to invoke a sub from another sub in Access and keep getting a "Compiler Error ByRef argument mismatch. I understand that it says the variable I am passing does not match with the one specified in the called sub. Here is my code. I have the variables firstDayOfStartMonth and firstDayOfEndMonth defined as dates and am passing them to the second proc deleteCurrentData(startDate As Date, endDate As Date).

Any help would be greatly appreciated.

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)

Answers


I have the variables firstDayOfStartMonth and firstDayOfEndMonth defined as dates

Actually, it is not quite true!

When you're using this declaration

Dim thisMonday, rptStartDate, rptEndDate, firstDayOfStartMonth, firstDayOfEndMonth As Date

only firstDayOfEndMonth is type of Date, other values are Variant. Try to use this declarations instead

Dim thisMonday As Date, rptStartDate As Date, rptEndDate As Date, firstDayOfStartMonth As Date, firstDayOfEndMonth As Date

this will fix the problem.

P.S. the same thing with

Dim monthName1, monthName2 As String

and

Dim startMonth, endMonth, curMonth   As Integer

Change them to

Dim monthName1 As String, monthName2 As String

and

Dim startMonth, endMonth As Integer, curMonth As Integer

accordingly


Need Your Help

Can I put an ASP.Net session ID in a hidden form field?

c# asp.net session yui

I'm using the Yahoo Uploader, part of the Yahoo UI Library, on my ASP.Net website to allow users to upload files. For those unfamiliar, the uploader works by using a Flash applet to give me more co...

Object or String(xml) over TCP

java java-ee networking tcp

I am implementing a low latency real time application which should push excessive messages.