I have two tables, Episodes and Seizures, with their respective Forms. On Episodes, I have a button the user clicks to open the seizure Form and its internal working is below. The problem is when the form is opened and filtered by parent form, the seizure form instead of filtering data, overwrites the first available record's incident number with the one that is passed. When I have the seizure table set to make sure Incident num is unique, it throws duplicate data error, and if it allows duplicate (Which is what i need), it creates new records. Suggestions?
Private Sub btnSeizure_Click()
If SeizureFormIsOpen() Then
CloseSeizureForm
Else
OpenSeizureForm
FilterSeizureForm
End If
End Sub
Private Sub FilterSeizureForm()
If Me.NewRecord Then
Forms![Seizures].DataEntry = True
Else 'Problem Code
Forms![Seizures].Filter = "[IncidentNum] = '" & Me.[incidentNum] & "' And [SourceTable] = 'Episode'"
Forms![Seizures].FilterOn = True
End If
End Sub
Private Sub OpenSeizureForm()
DoCmd.OpenForm "Seizures", acNormal, , , , acWindowNormal, Me.incidentNum & "&Episode"
End Sub
Private Sub CloseSeizureForm()
DoCmd.Close acForm, "Seizures"
End Sub
Private Function SeizureFormIsOpen()
SeizureFormIsOpen = (SysCmd(acSysCmdGetObjectState, acForm, "Seizures") And acObjStateOpen) <> False
End Function
The Seizure Form Has this for on load:
Private Sub Form_Load()
Dim argSplit() As String
argSplit = Split(CStr(Me.OpenArgs), "&")
'These are just Text boxes
Me.txtIncidentNum.Value = CStr(argSplit(0))
Me.sourceTable.Value = CStr(argSplit(1))
End Sub