Hi,
I have the following code that is supposed to make sure that when I move through different subforms, the record is retained via the ID primary key so I am still looking at the same record.
This works totally fine when I just open the "Navigation_Form" as it shows all records but when I want to view the results of a query, it retains the record but loses the filtered query when I go to a subform.
E.g, when the query loads in "Navigation_Form", record 1 of 20 from the query is shown (this has the ID of say 100)
when I move to record with the ID of 102, which is the 2nd record in the query and then move to a subform, record 102 is shown but out of 3000 as thats the total number of records in the database.
Ps I am using txtCurrentID to store the ID number as Navigation_Form is just a form to hold the subforms, the subfroms actually hold the ID and txtSearchQuery to save the query to apply to the subforms
Any help would be grateful.
Thanks
Code in Navigation_Form
Option Compare Database
Dim bQueryApplied As Boolean
Private Sub Form_Activate()
On Error GoTo ErrorHandler
If Not bQueryApplied Then
If Not IsNull(Me.txtSearchQuery) And Me.txtSearchQuery <> "" Then
If Me.NavigationSubform.Form.RecordSource <> Me.txtSearchQuery Then
Me.NavigationSubform.Form.RecordSource = Me.txtSearchQuery
Me.NavigationSubform.Form.Requery
End If
Else
If Me.NavigationSubform.Form.RecordSource <> "SELECT * FROM Coredata" Then
Me.NavigationSubform.Form.RecordSource = "SELECT * FROM Coredata"
Me.NavigationSubform.Form.Requery
End If
End If
bQueryApplied = True
End If
Exit Sub
ErrorHandler:
MsgBox "Error in Form_Activate: " & Err.Description, vbCritical
End Sub
Private Sub Form_Unload(Cancel As Integer)
Me.txtSearchQuery = Null
bQueryApplied = False
End Sub
Code in subforms
Option Compare Database
Private Sub Form_Current()
If CurrentProject.AllForms("Navigation_form").IsLoaded Then
Forms!Navigation_form!txtCurrentID = Me.ID
End If
End Sub
Private Sub Form_Load()
If CurrentProject.AllForms("Navigation_form").IsLoaded Then
Dim storedID As Variant
storedID = Forms!Navigation_form!txtCurrentID
If Not IsNull(storedID) Then
If Me.Recordset.NoMatch Or Me.Recordset!ID <> storedID Then
Me.Recordset.FindFirst "ID = " & storedID
End If
End If
End If
End Sub
I have the following code that is supposed to make sure that when I move through different subforms, the record is retained via the ID primary key so I am still looking at the same record.
This works totally fine when I just open the "Navigation_Form" as it shows all records but when I want to view the results of a query, it retains the record but loses the filtered query when I go to a subform.
E.g, when the query loads in "Navigation_Form", record 1 of 20 from the query is shown (this has the ID of say 100)
when I move to record with the ID of 102, which is the 2nd record in the query and then move to a subform, record 102 is shown but out of 3000 as thats the total number of records in the database.
Ps I am using txtCurrentID to store the ID number as Navigation_Form is just a form to hold the subforms, the subfroms actually hold the ID and txtSearchQuery to save the query to apply to the subforms
Any help would be grateful.
Thanks
Code in Navigation_Form
Option Compare Database
Dim bQueryApplied As Boolean
Private Sub Form_Activate()
On Error GoTo ErrorHandler
If Not bQueryApplied Then
If Not IsNull(Me.txtSearchQuery) And Me.txtSearchQuery <> "" Then
If Me.NavigationSubform.Form.RecordSource <> Me.txtSearchQuery Then
Me.NavigationSubform.Form.RecordSource = Me.txtSearchQuery
Me.NavigationSubform.Form.Requery
End If
Else
If Me.NavigationSubform.Form.RecordSource <> "SELECT * FROM Coredata" Then
Me.NavigationSubform.Form.RecordSource = "SELECT * FROM Coredata"
Me.NavigationSubform.Form.Requery
End If
End If
bQueryApplied = True
End If
Exit Sub
ErrorHandler:
MsgBox "Error in Form_Activate: " & Err.Description, vbCritical
End Sub
Private Sub Form_Unload(Cancel As Integer)
Me.txtSearchQuery = Null
bQueryApplied = False
End Sub
Code in subforms
Option Compare Database
Private Sub Form_Current()
If CurrentProject.AllForms("Navigation_form").IsLoaded Then
Forms!Navigation_form!txtCurrentID = Me.ID
End If
End Sub
Private Sub Form_Load()
If CurrentProject.AllForms("Navigation_form").IsLoaded Then
Dim storedID As Variant
storedID = Forms!Navigation_form!txtCurrentID
If Not IsNull(storedID) Then
If Me.Recordset.NoMatch Or Me.Recordset!ID <> storedID Then
Me.Recordset.FindFirst "ID = " & storedID
End If
End If
End If
End Sub