Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clear Contents of Subform From Mainform

Status
Not open for further replies.

sallieann

Programmer
Sep 2, 2003
28
GB
Hi, I have a main form with input boxes for entering search criteria & the results are output to a subform. When the user clicks clear to start a new search the input boxes clear. I would also like my search results subform to clear too. My code is as follows;

Private Sub Clear_Click()

[txtSearch1] = ""
[txtSearch2] = ""
[txtSearch3] = ""

End Sub

I understand that I need to refer to the subform with something like

Me![search_results_subform].Form = clear

but I cannot find the correct syntax. Can anybody help?! Many thanks in advance
 
Hi,

That is the right syntax to refer to the subform object, but how you clear the subform depends on how your results are generated and displayed.

I would imagine you are creating a sql query based on the 3 text boxes.

Could you be more specific about how you show the search results?

Dean :)
 
Hi there, thanks for your quick reply. My complete code for the search button is as follows;

Private Sub search_Click()

Dim MySQL As String
Dim MyCriteria As String
Dim MyRecordSource As String
Dim ArgCount As Integer

MySQL = "SELECT * FROM [parts] WHERE "

AddToWhere [txtSearch1], "[sap_code]", MyCriteria, ArgCount
AddToWhere [txtSearch2], "[part]", MyCriteria, ArgCount
AddToWhere [txtSearch3], "[part_details]", MyCriteria, ArgCount

If MyCriteria = "" Then
MyCriteria = "True"
End If

MyRecordSource = MySQL & MyCriteria

If Me![txtSearch1] <> &quot;&quot; Then
MyRecordSource = MySQL & MyCriteria & &quot; ORDER BY [sap_code]&quot;
ElseIf Me![txtSearch2] <> &quot;&quot; Then
MyRecordSource = MySQL & MyCriteria & &quot; ORDER BY [part]&quot;
ElseIf Me![txtSearch3] <> &quot;&quot; Then
MyRecordSource = MySQL & MyCriteria & &quot; ORDER BY [part_details]&quot;
Else
MyRecordSource = MySQL & MyCriteria & &quot; ORDER BY [sap_code]&quot;
End If

Me![search_results_subform].Form.RecordSource = MyRecordSource

Exit_VIEW_Click:
Exit Sub

Err_VIEW_Click:
MsgBox Error$
Resume Exit_VIEW_Click

End Sub

Hope this makes it clearer!
 
Hi,

Can you set the recordsource to something that will return no records, ie:
Code:
Me![search_results_subform].Form.RecordSource = &quot;SELECT * FROM [parts] WHERE PartNo = 0&quot;

or something like that.

Dean.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top