I am trying to build multi field search into an Access 2007 database I have with 2 forms & 1 query. I have a form for entering the details & a query, with criteria such as 'Like "*" & [Forms]![frmSearch]![txtFirstName] & "*"' and 'Like "*" & [Forms]![frmSearch]![txtLastName] & "*"'. Rather than running the query from the form, & getting a datasheet display of results, I have made a 2nd form which will display the query results. The Search form has a button to open this Results form & all works well.
What I would like is to be able to close the Search form when I click the button to open the Results form. In the Search form, if I put DoCmd.Close before DoCmd.OpenForm in the code for the button, it closes my Search form which is feeding the query for the Results form before the results are displayed.
How could I get it to work the way I want? I hope Ive explained this well enough & its not too confusing.
The code is:
What I would like is to be able to close the Search form when I click the button to open the Results form. In the Search form, if I put DoCmd.Close before DoCmd.OpenForm in the code for the button, it closes my Search form which is feeding the query for the Results form before the results are displayed.
How could I get it to work the way I want? I hope Ive explained this well enough & its not too confusing.
The code is:
Code:
Private Sub cmdOpenResultsForm_Click()
On Error GoTo Err_cmdOpenResultsForm_Click
Dim stDocName As String
Dim stLinkCriteria As String
DoCmd.Close
stDocName = "frmResults"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_cmdOpenResultsForm_Click:
Exit Sub
Err_cmdOpenResultsForm_Click:
MsgBox Err.Description
Resume Exit_cmdOpenResultsForm_Click