April15Hater
Accountant
- Local time
- Today, 16:17
- Joined
- Sep 12, 2008
- Messages
- 349
Hey guys-
I'm pretty new to using arrays and I find them quite helpful, but this one has me really stumped. When I run 'MyVar = PayRates(0)' in the calling code, I get a 'Type Mismatch' error.
This is the abridged version of the calling code
Here is the full function that compiles the array.
I'm pretty new to using arrays and I find them quite helpful, but this one has me really stumped. When I run 'MyVar = PayRates(0)' in the calling code, I get a 'Type Mismatch' error.
This is the abridged version of the calling code
Code:
Function ReconcileTimesheet(ProductionID As Long)
Dim PayRates As Variant
PayRates = GetHourlyProduction(rsLiveData!CompleteDate, rsLiveData!ProductionInputDetailID, rsLiveData!ContractorID)
MyVar = PayRates(0)
End Function
Code:
Public Function GetHourlyProduction(datCompleteWeek As Date, lngProductionDetailID As Long, ContractorID As Long, Optional douProposedChange) As Variant
Dim rsProduction, rsHours As ADODB.Recordset
Dim douProductionRate, douDefaultRate As Double
Dim PayRates(0 To 1)
Set rsProduction = New ADODB.Recordset
Set rsHours = New ADODB.Recordset
douDefaultRate = DLookup("DefaultRate", "tblProductionDetailTimesheet", "ProductionInputDetailID = " & lngProductionDetailID)
douProductionRate = DLookup("Cost", "tblProductionDetailTimesheet", "ProductionInputDetailID = " & lngProductionDetailID)
If IsMissing(douProposedChange) Then douProposedChange = 0
With rsHours
.ActiveConnection = CurrentProject.Connection
.Source = "SELECT sum(iif(TimeInDate < TimeOutDate, TimeOut - TimeIN + 24, TimeOut - TimeIn)) as TotalHours " _
& "FROM tblContractorHours " _
& "WHERE ContractorID = " & ContractorID & " AND " _
& "TimeInDate BETWEEN #" & datCompleteWeek - 6 & "# AND #" & datCompleteWeek & "#;"
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open
douHourly = (douDefaultRate * !TotalHours)
End With
With rsProduction
.ActiveConnection = CurrentProject.Connection
.Source = "SELECT sum((tblProductionDetailTimesheet.Cost * tblProductionDetailTimesheet.ProductionUnits)) as ProductionCost " _
& "FROM tblProductionTimesheet INNER JOIN tblProductionDetailTimesheet ON tblProductionTimesheet.ProductionID = tblProductionDetailTimesheet.ProductionID " _
& "WHERE ContractorID = " & ContractorID & " AND " _
& "(CompleteDate BETWEEN #" & datCompleteWeek - 6 & "# AND #" & datCompleteWeek & "# OR tblProductionDetailTimesheet.Chargeback = True);"
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open
douProduction = !ProductionCost + douProposedChange * douProductionRate
End With
PayRates(0) = douHourly
PayRates(1) = Round(douProduction, 2)
DetermineHoursProduction = PayRates
End Function