In ms access, I have a mainform with 2 subforms. SubformA is a continuous form with record title and a transparent button overlay for each record. SubformB contains the detail of the selected record (this is on tabcontrol elsewhere within the mainform, mimicking a popup overlay).
What I want to happen is:
1. Clicking a record subformA displays subformB and filters it to that record.
2. Moving through records on subformA updates so that subformB always displays the corresponding record.
3. Clicking a record on subformA hides subformB again ONLY IF it is the record that is currently being displayed.
However I cannot work out how I can test for if the current record is the one that was clicked because as soon as I click the button, if it is not the current record, the current event fires first, making it the current record, and hence always hiding subformB.
I tried using a variable to check at the start and end of the current event if the id on subformB stays the same. However, the current event of course does not trigger in the situations where the record has not changed, which is when I need to test this variable.
Stripped down/pseudocode in subformA for what I have tried to do:
Sub Form_Current
If subformB.Visible Then set filter on subformB to ID = subfromA.ID
End Sub
Sub cmdButton_Click
If subformB.Visible Then
If subformB.ID = subformA.ID Then
Hide subformB
Else
'code never gets to here because the condition is always true
'do nothing - current event has already set the filter
End If
Else
Unhide subformB
Set filter to ID = subformA.ID
End If
End Sub
Is anybody able to help me here? Thanks.
EDIT: what I am asking is how can I test the current record ID against the record ID of the record where the command button was clicked - but the record ID when clicking the button is of course just taking the new current record ID. Therefore it is comparing old current record ID to new current record ID, the problem being how do I store the old ID but prevent it from being updated again before the condition is tested.