openform action cancelled

wilson1001

Registered User.
Local time
Today, 08:22
Joined
Mar 24, 2003
Messages
17
Hello

I have created a form that accepts input via a text box( txtfilter) and command button (cmdsearch).
The inputed term is used to search all fields in my table (parts) and the results of the search are displayed in a list box (lstresults)
When a result in the list box is clicked on it should display the record on a new form.

My problem – When a result is clicked on I receive the following error and the form does not open.

Run-time error 2501
"The openform action was cancelled"

Can anyone tell me if I have messed up the syntax on my “Docmd.openform” ?

Thanks
Pete

My code:

Private Sub cmdSearch_Click()
If IsNull(Me.txtfilter) Then
MsgBox "You have not entered any text.", vbExclamation, "Attention"
Exit Sub
End If
With LSTRESULTS
.RowSource = "Select * FROM parts WHERE ((([part no]) Like '*" & Me.txtfilter & "*') OR (([description]) Like '*" & Me.txtfilter & "*') OR (([bin location]) Like '*" & Me.txtfilter & "*')OR (([in stock]) Like '*" & Me.txtfilter & "*')OR (([price 1]) Like '*" & Me.txtfilter & "*')OR (([price 2]) Like '*" & Me.txtfilter & "*')OR (([price 3]) Like '*" & Me.txtfilter & "*') );"

.Requery
End With
End Sub

Private Sub Command54_Click()

End Sub

Private Sub Form_AfterUpdate()

End Sub

Private Sub lstResults_AfterUpdate()
DoCmd.OpenForm "parts", acNormal, , "[part no] = " & LSTRESULTS.Column(0)

End Sub


Private Sub Close_search_form_Click()
On Error GoTo Err_Close_search_form_Click


DoCmd.close

Exit_Close_search_form_Click:
Exit Sub

Err_Close_search_form_Click:
MsgBox Err.Description
Resume Exit_Close_search_form_Click

End Sub
Private Sub List70_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[part no] = " & Str(Nz(Me![List70], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub
 
what do you have on the Form_Open event of the parts form?
 
Nothing!

I can't even find a Form_Open event action on the parts form properties.
 
Change this event to an On_Click Event of the listbox instead

Code:
Private Sub lstResults_AfterUpdate() 
DoCmd.OpenForm "parts", acNormal, , "[part no] = " & LSTRESULTS.Column(0) 
End Sub 

[b]to[/b]

Private Sub lstResults_OnClick() 
DoCmd.OpenForm "parts", acNormal, , "[part no] = " & LSTRESULTS.Column(0) 
End Sub

and change
Code:
[b]this[/b]
DoCmd.close 

[b]to this[/b]
Docmd.close acform,"NameOfSearchForm"
 
Hmmmmm.

I made thoses changes but now when i click on a result in the listbox there is no action at all, not even an error message.
 
You need to change the event procedures in the control themselves as well to tell the controls what to do when you perform a particular event. In the form design view, in the listbox lstresults, make sure that the On Click event has [event procedure] and the After Update has nothing. Click on the ... to make sure of the code behind the events.
 
Try
DoCmd.OpenForm "parts", acNormal, , "[part no] = " & " ' " & LSTRESULTS.Column(0) & " ' "
 

Users who are viewing this thread

Back
Top Bottom