I ran into an issue a few years back that I found a quick, but ugly fix for. Now that fix is causing problems and I want to see if there is a cleaner way to do it.
Problem:
I have two subforms. 1 is a form that shows "Available Staff" based on certain criteria (Date, Time of Day). The 2nd form shows which staff members have already been "Assigned". When a staff member is assigned they are removed from the "Available Staff" form and their assignment appears in the "Assigned" form. The problem I am having is with the subforms registering the change. I know that the change is happening based upon the tables, but there seems to be a disconnect with the subforms. The only way I have gotten the subforms to register the change is by requerying within a loop until the record count changes. It's not clean, can take forever and has recently started to crash the database. Is there something that I am missing here?
Problem:
I have two subforms. 1 is a form that shows "Available Staff" based on certain criteria (Date, Time of Day). The 2nd form shows which staff members have already been "Assigned". When a staff member is assigned they are removed from the "Available Staff" form and their assignment appears in the "Assigned" form. The problem I am having is with the subforms registering the change. I know that the change is happening based upon the tables, but there seems to be a disconnect with the subforms. The only way I have gotten the subforms to register the change is by requerying within a loop until the record count changes. It's not clean, can take forever and has recently started to crash the database. Is there something that I am missing here?
Code:
Private Sub ctlAssign_Click()
Dim RecCount As Integer
TempVars.Add ("DateVar"), Me.Text43.Value
Me.RecordsetClone.MoveLast
RecCount = Me.RecordsetClone.RecordCount
AssignStaff Me.StaffID.Value, TempVars.Item("CenterVar")
Do Until Me.RecordsetClone.RecordCount = RecCount - 1
Forms!f_Navigation!f_FieldStaff.Requery
Loop
Forms!f_Navigation!f_CenterFieldStaff.Requery
Forms!f_Navigation!f_Center.Requery
Forms!f_Navigation!f_Center.Form.cmbLead.Requery
Me.cmdFilter.SetFocus
End Sub
Code:
Public Function AssignStaff(strID As String, CenID As String)
Dim strSQL As String, MyDB As New ADODB.Connection, rstProjTable As
rstProjTable.Open "select * from T_SRM_Schedule", MyDB, adOpenKeyset, adLockPessimistic
rstProjTable.AddNew
rstProjTable("StaffID").Value = strID
rstProjTable("SchoolID").Value = CenID
rstProjTable("AssignedDate").Value = TempVars.Item("DateVar")
rstProjTable("AMPM").Value = TempVars.Item("TimeVar")
rstProjTable("AddedBy").Value = TempVars.Item("SRMVar")
rstProjTable("AddedDate").Value = Now
rstProjTable.Update
rstProjTable.Close
DoEvents
Set rstProjTable = Nothing
MyDB.Close
Set MyDB = Nothing
End Function