Hi, I haven't used Access in a while so this may be quite an easy fix for some of you.
I have 15 reps in a table and am basing the report on their names. I have VBS code which does a lot of different calculcations for each group (the rep name). But in print preview, the first rep's totals are displayed for all of the other reps. I receive no processing errors and do check for BOF and EOF on all recordsets. What can the problem be? Here is a portiion of the code.
Sub Fill_Fields()
Dim dbs As Database
Dim rst As Recordset
Dim qdf As QueryDef
Dim prm As Parameter
On Error GoTo HandleErr
Set dbs = CurrentDb()
Set qdf = dbs.QueryDefs("qryTotAcctsinDate_Prospects"
For Each prm In qdf.Parameters
prm.Value = Eval(prm.Name)
Next prm
Set rst = qdf.OpenRecordset(dbOpenDynaset)
If Not rst.BOF And Not rst.EOF Then
If rst.EOF Then
Me!txtCtNumAccts = 0
Else
rst.MoveLast
Me!txtCtNumAccts = rst.RecordCount
End If
Else
Me!txtCtNumAccts = 0
End If
rst.Close
Set qdf = dbs.QueryDefs("qryTotalSales_NonContacted"
For Each prm In qdf.Parameters
prm.Value = Eval(prm.Name)
Next prm
Set rst = qdf.OpenRecordset(dbOpenDynaset)
If Not rst.BOF And Not rst.EOF Then
If IsNull(rst.Fields("TotalSales"
) Then
Me!txtNoCtTotSales = 0#
Else
Me!txtNoCtTotSales = rst.Fields("TotalSales"
End If
Else
Me!txtNoCtTotSales = 0#
End If
rst.Close
Set rst = Nothing
Set prm = Nothing
dbs.Close
HandleErr:
MsgBox "Error Num: " & Err.Number & " Desc: " & Err.Description
' set any existing recordsets to nothing
If Not rst Is Nothing Then
Set rst = Nothing
End If
If Not prm Is Nothing Then
Set prm = Nothing
End If
If Not dbs Is Nothing Then
Set dbs = Nothing
End If
Exit Sub
End Sub
I have 15 reps in a table and am basing the report on their names. I have VBS code which does a lot of different calculcations for each group (the rep name). But in print preview, the first rep's totals are displayed for all of the other reps. I receive no processing errors and do check for BOF and EOF on all recordsets. What can the problem be? Here is a portiion of the code.
Sub Fill_Fields()
Dim dbs As Database
Dim rst As Recordset
Dim qdf As QueryDef
Dim prm As Parameter
On Error GoTo HandleErr
Set dbs = CurrentDb()
Set qdf = dbs.QueryDefs("qryTotAcctsinDate_Prospects"
For Each prm In qdf.Parameters
prm.Value = Eval(prm.Name)
Next prm
Set rst = qdf.OpenRecordset(dbOpenDynaset)
If Not rst.BOF And Not rst.EOF Then
If rst.EOF Then
Me!txtCtNumAccts = 0
Else
rst.MoveLast
Me!txtCtNumAccts = rst.RecordCount
End If
Else
Me!txtCtNumAccts = 0
End If
rst.Close
Set qdf = dbs.QueryDefs("qryTotalSales_NonContacted"
For Each prm In qdf.Parameters
prm.Value = Eval(prm.Name)
Next prm
Set rst = qdf.OpenRecordset(dbOpenDynaset)
If Not rst.BOF And Not rst.EOF Then
If IsNull(rst.Fields("TotalSales"
Me!txtNoCtTotSales = 0#
Else
Me!txtNoCtTotSales = rst.Fields("TotalSales"
End If
Else
Me!txtNoCtTotSales = 0#
End If
rst.Close
Set rst = Nothing
Set prm = Nothing
dbs.Close
HandleErr:
MsgBox "Error Num: " & Err.Number & " Desc: " & Err.Description
' set any existing recordsets to nothing
If Not rst Is Nothing Then
Set rst = Nothing
End If
If Not prm Is Nothing Then
Set prm = Nothing
End If
If Not dbs Is Nothing Then
Set dbs = Nothing
End If
Exit Sub
End Sub