What is the most efficient way to convert a recordset that contains only one field into a VBA variable. In the following example I ‘m looking for the highest expiration date in an access table. This obviously returns a single value. But the subsequent code I use is rather elaborate to assign that valu to a VBA variable. Can it be done in another way?
Dim datMaximum As Date
Dim cmdADO As ADODB.Command
Set cmdADO = New ADODB.CommandWith cmdADO
.ActiveConnection = CurrentProject.Connection
.CommandText = “SELECT TOP 1 qryA.ExpDate as ExDay FROM qryA ” & _
“ORDER BY qryA.ExpDate DESC”
End WithDim rsVD As ADODB.Recordset
Set rsVD = New ADODB.Recordset
rsVD.Open cmdADO, , adOpenKeyset, adLockOptimisticWith rsVD
Select Case Not (.EOF And .BOF)
Case True
.MoveFirst
datMaximum = .Fields(“ExDay”)
.Close
Set rsVD = Nothing
Case False
‘no records found
Exit Sub
End Select
End With