S
Steve Perrins
When I query across two tables the RecordCount = 1 when there are in fact 13
records returned :-
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSql As String
Dim strOuts() As String
Dim nBudg() As Currency
Dim nTBudg As Currency
Dim nActual() As Currency
Dim nTActual As Currency
Dim nAlts() As Currency
Dim nTAlts As Currency
Dim nFDiff As Currency
Dim nODiff As Currency
Dim nCount As Integer
' Get the budget outgoings and amount
Set db = CurrentDb
strSql = "SELECT proj_outs.ID, proj_outs.outgoing, proj_outs.cost_type,
proj_outs.amount, proj_outs.adjustment, " & _
"proj_budg.budg_status " & _
"FROM proj_outs, proj_budg WHERE proj_outs.ID=proj_budg.POUTID
" & _
"AND proj_outs.PROJID=" & strID & " AND
proj_outs.inc_inbudg=Yes;"
Set rs = db.OpenRecordset(strSql)
If rs.RecordCount = 0 Then
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing
Exit Sub
End If
ReDim strOuts(rs.RecordCount, 4)
ReDim nBudg(rs.RecordCount)
ReDim nActual(rs.RecordCount)
ReDim nAlts(rs.RecordCount)
nCount = 0
nTBudg = 0
nTActual = 0
nFDiff = 0
nODiff = 0
nTAlts = 0
rs.MoveFirst
Do Until rs.EOF
' Lines commented out for debugging
' strOuts(nCount, 0) = rs!outgoing
' strOuts(nCount, 2) = rs!ID
' If StrComp("Purchase", rs!cost_type, 1) = 0 Then
' strOuts(nCount, 1) = "P"
' End If
' If StrComp("Expense", rs!cost_type, 1) = 0 Then
' strOuts(nCount, 1) = "E"
' End If
' If StrComp("Finance", rs!cost_type, 1) = 0 Then
' strOuts(nCount, 1) = "F"
' End If
' If StrComp("Finished", rs!budg_status, 1) = 0 Then
' strOuts(nCount, 3) = "F"
' Else
' strOuts(nCount, 3) = "O"
' End If
' nBudg(nCount) = rs!amount
' nTBudg = nTBudg + nBudg(nCount)
' nAlts(nCount) = rs!adjustment
' nTAlts = nTAlts + nAlts(nCount)
rs.MoveNext
nCount = nCount + 1
Loop
rs.Close
After looping through the recordset the recordcount is correct.
As I am using the record count to set the size of the arrays in my code, I
am going to have to loop through all records first then size the arrays,
then MoveFirst and then loop through the recordset again processing the
records.
Is this a bug or am I doing something wrong here?
Regards,
Steve Perrins
records returned :-
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSql As String
Dim strOuts() As String
Dim nBudg() As Currency
Dim nTBudg As Currency
Dim nActual() As Currency
Dim nTActual As Currency
Dim nAlts() As Currency
Dim nTAlts As Currency
Dim nFDiff As Currency
Dim nODiff As Currency
Dim nCount As Integer
' Get the budget outgoings and amount
Set db = CurrentDb
strSql = "SELECT proj_outs.ID, proj_outs.outgoing, proj_outs.cost_type,
proj_outs.amount, proj_outs.adjustment, " & _
"proj_budg.budg_status " & _
"FROM proj_outs, proj_budg WHERE proj_outs.ID=proj_budg.POUTID
" & _
"AND proj_outs.PROJID=" & strID & " AND
proj_outs.inc_inbudg=Yes;"
Set rs = db.OpenRecordset(strSql)
If rs.RecordCount = 0 Then
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing
Exit Sub
End If
ReDim strOuts(rs.RecordCount, 4)
ReDim nBudg(rs.RecordCount)
ReDim nActual(rs.RecordCount)
ReDim nAlts(rs.RecordCount)
nCount = 0
nTBudg = 0
nTActual = 0
nFDiff = 0
nODiff = 0
nTAlts = 0
rs.MoveFirst
Do Until rs.EOF
' Lines commented out for debugging
' strOuts(nCount, 0) = rs!outgoing
' strOuts(nCount, 2) = rs!ID
' If StrComp("Purchase", rs!cost_type, 1) = 0 Then
' strOuts(nCount, 1) = "P"
' End If
' If StrComp("Expense", rs!cost_type, 1) = 0 Then
' strOuts(nCount, 1) = "E"
' End If
' If StrComp("Finance", rs!cost_type, 1) = 0 Then
' strOuts(nCount, 1) = "F"
' End If
' If StrComp("Finished", rs!budg_status, 1) = 0 Then
' strOuts(nCount, 3) = "F"
' Else
' strOuts(nCount, 3) = "O"
' End If
' nBudg(nCount) = rs!amount
' nTBudg = nTBudg + nBudg(nCount)
' nAlts(nCount) = rs!adjustment
' nTAlts = nTAlts + nAlts(nCount)
rs.MoveNext
nCount = nCount + 1
Loop
rs.Close
After looping through the recordset the recordcount is correct.
As I am using the record count to set the size of the arrays in my code, I
am going to have to loop through all records first then size the arrays,
then MoveFirst and then loop through the recordset again processing the
records.
Is this a bug or am I doing something wrong here?
Regards,
Steve Perrins