Hi, I have a form (CandidateSearch Subform) that uses a query as it's datasource. The query has paramaters that come from a second form (CandidateSearch), and these paramaters are used to decide what records to include in the query and therefore to show in the results. The names are misleading, CandidateSearch Subform is not a Subform of CandidateSearch. It used to be, before I wanted my search paramaters on a separate form.
I am trying to implement my Search form so that the user can enter the parameters, click on "Do Search" button, and then have either: 1) The results form open and show the results, if it is not open. Or 2) The results form Requery it's data to meet the new criteria, if it is already open.
The code I used to do this before is shown below. Note, that I simply try to reference the form, and then OnError I know that the form reference failed, so I then open the form. This is obviously not ideal. But for a while, it worked.
Private Sub DoCandidateSearch_Click()
On Error GoTo TestError
If (IsNull(Forms![CandidateSearch Subform]) = False) Then
Forms![CandidateSearch Subform].Requery
End If
Test_Exit:
Exit Sub
TestError:
DoCmd.OpenForm "CandidateSearch Subform"
Resume Test_Exit
End Sub
But now I want to change some properties of the results form based on the user's criteria also. Ie: Change the color of the fields that the user included as a parameter. So I really need a better way to determine if the form is already open. If not, I have to put the color changing code in both the error handler and the main subroutine.
I am trying to implement my Search form so that the user can enter the parameters, click on "Do Search" button, and then have either: 1) The results form open and show the results, if it is not open. Or 2) The results form Requery it's data to meet the new criteria, if it is already open.
The code I used to do this before is shown below. Note, that I simply try to reference the form, and then OnError I know that the form reference failed, so I then open the form. This is obviously not ideal. But for a while, it worked.
Private Sub DoCandidateSearch_Click()
On Error GoTo TestError
If (IsNull(Forms![CandidateSearch Subform]) = False) Then
Forms![CandidateSearch Subform].Requery
End If
Test_Exit:
Exit Sub
TestError:
DoCmd.OpenForm "CandidateSearch Subform"
Resume Test_Exit
End Sub
But now I want to change some properties of the results form based on the user's criteria also. Ie: Change the color of the fields that the user included as a parameter. So I really need a better way to determine if the form is already open. If not, I have to put the color changing code in both the error handler and the main subroutine.