The code was written by someone else on the board. The code is in the main form so that when the subform (call listing subform) for # of calls has new information and they press the F9 key it updates the main form. The same goes for the # of samples (workorder subform).
I hope this is what you wanted as I'm not very good at programming - yet.
Here is the code:
Option Compare Database
Function IsLoaded(ByVal strFormName As String) As Integer
' Returns True if the specified form is open in Form view or Datasheet view.
Const conObjStateClosed = 0
Const conDesignView = 0
If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> conObjStateClosed Then
If Forms(strFormName).CurrentView <> conDesignView Then
IsLoaded = True
End If
End If
End Function
Function TotalSamples(pContactID As Long) As Integer
Dim db As Database
Dim LSQL As String
Dim Lrs As Recordset
Set db = CurrentDb()
'Retrieve the number of samples for the ContactID (represented by pContactID)
LSQL = "select sum([# of Samples]) from Workorders"
LSQL = LSQL & " where ContactID = " & pContactID
Set Lrs = db.OpenRecordset(LSQL)
'Records are found
If (Lrs.EOF = False) And (IsNull(Lrs(0)) = False) Then
TotalSamples = Lrs(0)
Else
TotalSamples = 0
End If
End Function
Function TotalCalls(pContactID As Long) As Integer
Dim db As Database
Dim LSQL As String
Dim Lrs As Recordset
Set db = CurrentDb()
'Retrieve the number of calls for the ContactID (represented by pContactID)
LSQL = "select count(*) from Calls"
LSQL = LSQL & " where ContactID = " & pContactID
Set Lrs = db.OpenRecordset(LSQL)
'Records are found
If (Lrs.EOF = False) And (IsNull(Lrs(0)) = False) Then
TotalCalls = Lrs(0)
Else
TotalCalls = 0
End If
End Function
Thanks for any ideas!