Hi,
I am trying to generate an quote number using a query like:
stsql = "SELECT Max(Val(Mid([Quote],4))) AS [Number] From [Quote Numbers] GROUP BY Left([Quote],3) HAVING (((Left([Quote],3))='HTR'));"
The code that runs this is:
rstProject.Open stSQL, CurrentProject.Connection, adOpenForwardOnly
With rstProject
If .RecordCount = -1 Then
fnNewProjectNumber = 1
Else
.MoveFirst
fnNewProjectNumber = !Number + 1
End If
.Close
End With
When I first ran it, I thought the RecordCount came back as -1 because there were no records, but now the query does return a record, but the RecordCount is still -1.
If an aggregate query always returns -1, how can you handle the case when there are no records?
Our community of experts have been thoroughly vetted for their expertise and industry experience.