C
Chaplain Doug
I thought that I would make my code more efficient by
using built-in functions. However, in this case shorter
code using built-in function was slower why?
*****
It Was
*****
If TN = "F" Then
TableName = "[Female Cycles]"
Else
TableName = "[Male Cycles]"
End If
Criteria = "[SAPCycle]= " & Str(CN)
strSQL = "SELECT * FROM " + TableName + " WHERE " &
Criteria
Set rst = dbs.OpenRecordset(strSQL)
If rst.RecordCount = 1 Then 'Found a matching record
rst.MoveFirst
With rst
CycleStart = ![StartDate]
End With
Else
CycleStart = "1/1/2000"
End If
*******
I changed it to (which was slower)
*******
If TN = "F" Then
TableName = "[Female Cycles]"
Else
TableName = "[Male Cycles]"
End If
Criteria = "[SAPCycle]= " & Str(CN)
CycleStart=Nz(DLookup
("[CycleStart]",TableName,Criteria),#1/1/2000#)
using built-in functions. However, in this case shorter
code using built-in function was slower why?
*****
It Was
*****
If TN = "F" Then
TableName = "[Female Cycles]"
Else
TableName = "[Male Cycles]"
End If
Criteria = "[SAPCycle]= " & Str(CN)
strSQL = "SELECT * FROM " + TableName + " WHERE " &
Criteria
Set rst = dbs.OpenRecordset(strSQL)
If rst.RecordCount = 1 Then 'Found a matching record
rst.MoveFirst
With rst
CycleStart = ![StartDate]
End With
Else
CycleStart = "1/1/2000"
End If
*******
I changed it to (which was slower)
*******
If TN = "F" Then
TableName = "[Female Cycles]"
Else
TableName = "[Male Cycles]"
End If
Criteria = "[SAPCycle]= " & Str(CN)
CycleStart=Nz(DLookup
("[CycleStart]",TableName,Criteria),#1/1/2000#)