Open a form after searching for records

D

daniel

This is what I would like to do:

Have user enter a part of an ID

Search the ID and bring up a continuous form with ID's
that contain that part.

If there are no ID's that match, cancel the openform event
or close the form if it is open.

How could I go about that?

Thanks
Dan
 
A

Allen Browne

Use the AfterUpdate event procedure of your text box to open the form:

Private Sub txtWotPart_AfterUpdate
dim strWhere As String
strWhere = "[PartID] Like ""*" & Me.txtWotPart & "*"""
DoCmd.OpenForm "MyForm", WhereCondition:=strWhere
End Sub

Use the Open event of the form to cancel if there are no matches:

Private Sub Form_Open(Cancel As Integer)
If Me.RecordsetClone.RecordCount = 0 Then
Cancel = True
MsgBox "No matches"
End If
End Sub

Note that this will not work correctly if the form is already open.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top