Sums in footers of continuous forms are very picky. Any code error anywhere in the module gives Access an opportunity to choke on them.
SO, don't get your sums that way. Here's some code in the attached DB that gets the sums via VBA.
LengthCal Forum-davegri-v01.zip
Code:
Option Compare Database
Option Explicit
Dim strUserName As String
Dim strInitial As String
Dim strUserPCNo As String
Dim strPipIso, strZone, StrSegment As String
Dim CmbSize As New FindAsYouTypeCombo
'<<<<<<<frmSingleLenCal
Private Function fcnGetFooterTots()
Call fcnMakeNamedQuery("qFooterTots", Me.RecordSource)
Me.txtTotalPipeLenght = DSum("P_lgth", "qFooterTots")
Me.txtTotalTLN = DSum("TLN", "qFooterTots")
End Function
'Public Sub ClearClipBoard()
' Dim oData As New DataObject 'object to use the clipboard
And here's the fcnMakeNamedQuery in Mod_davegri:
Code:
Option Compare Database
Option Explicit
'---------------------------------------------------------------------------------------
' Procedure : fcnMakeNamedQuery
' DateTime : 9/26/2006 20:57
' Author : davegri
' Purpose : Attach new SQL property to an existing querydef. If the Query doesn't exist,
' : create it with the passed SQL.
'---------------------------------------------------------------------------------------
'
Function fcnMakeNamedQuery(qName As String, strPassedSQL As String)
Dim qthisQuery As DAO.QueryDef
If DCount("Name", "MSysObjects", "[Name] = " & Chr$(39) & qName & Chr$(39)) = 0 Then
Set qthisQuery = CurrentDb.CreateQueryDef(qName, strPassedSQL)
Else
Set qthisQuery = CurrentDb.QueryDefs(qName)
qthisQuery.SQL = strPassedSQL
End If
Application.RefreshDatabaseWindow
Set qthisQuery = Nothing
End Function
And here's what kicks off the process:
Code:
Public Sub FilterForm()
Dim strsql As String
Dim numbertoshow As Integer
Dim TotalRecords As Integer
TotalRecords = DCount("*", "qryLenCalc")
strsql = "Select * from qryLenCalc Order By LenID"
If cmboNumber <> "<All>" And Not IsNull(Me.cmboNumber) Then
numbertoshow = CInt(Me.cmboNumber)
'Debug.Print TotalRecords - numbertoshow
If TotalRecords > numbertoshow Then
strsql = "Select * from qryLenCalc where LenID NOT IN (Select Top " & (TotalRecords - numbertoshow) & " LenID from qryLenCalc Order By LenID) Order By LenID"
End If
End If
Me.RecordSource = strsql
Call fcnGetFooterTots
'Debug.Print strSQL
End Sub