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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run Time Error 2501 - OpenForm action cancelled (???)

Status
Not open for further replies.

MrKABC

Technical User
Jul 20, 2001
54
US
Hello all!

I receive the following error message in Access 97:

"Run Time Error 2501: The OpenForm action was canceled. You used a method of the DoCmd object to carry out an action in Visual Basic, but then clicked Cancel in a dialog box. For example, you used the Close method to close a changed form, then clicked Cancel in a dialog box that asks if you want to save the changes you made to this form."

I then get the option to debug. When I exercise that option, this line of code is highlighted:

DoCmd.OpenForm "LOUForm", , , "ClaimNo='" & strID & "'", acFormEdit

A bit of background about what is going on here: My search form has a listbox and text box. Typing in a value in the text box attempts to find a matching value (claim number) in the list box. If a value is found, double clicking the list box will open another (editing) form "LOUForm" matching the value in the list box. Clear as mud?

My first question: Did I screw up the syntax above? I didn't cancel anything that I am aware of!!! ,=]

Here is the entire routine for reference. Note that global variables were defined elsewhere and are not an issue in this problem.

Code:
Private Sub btnOK_Click()
'Selects the record to modify
    For intCount = 0 To Me.ClaimList.ItemsSelected.Count - 1
        intCurrentItem = Me.ClaimList.ItemsSelected(intCount)
        strID = Me.ClaimList.Column(2, intCurrentItem)
    Next
    
    If txtClaimNo = "" Then 'This procedure kicks you back to the list box
    intResponse = MsgBox("You must specify a claim to open!", vbOKOnly, "ERROR!")
    ClaimList.SetFocus
    Exit Sub
    End If

intStatus = 1
DoCmd.OpenForm "LOUForm", , , "ClaimNo='" & strID & "'", acFormEdit
DoCmd.GoToControl "txtClaimNo"
End Sub

Thanks for any and all assistance in advance! <smile>

A.
 
Hi!

Just a thought, do you have any code in LOUform's on open event that returns cancel=true? (some validation perhaps?)

That's the only way I seem to be able to reproduce that error/behaviour.

Nother thingie:
As far as I can see, the docmd line seems appropriate, but I'm a bit unsure of the looping thru the list thingie. ItemsSelectes is used for multiselect listboxes, and to me it seems only one item is needed (filtered to LOUform), a syntax like:

[tt]Me!ClaimList.Column(2)[/tt]

would normally provdide third column value of the selected item in &quot;ordinary&quot; listbox (not multiselect). Though I don't think this should provide any error (unless validation in LOUform's on open)

HTH Roy-Vidar
 
1. Make sure your listbox has at least 3 columns
2. Make sure the 3-rd column has a value
3. Your For...Next loop always selects the last entry selected in the listbox. Is it multiselect? If not, you don't need the loop.

HTH


[pipe]
Daniel Vlas
Systems Consultant

 
Thank you Roy and Dan for your help.

In response to your questions:

No, I have nothing at all in LOUForm's ON OPEN event. There is nothing with a CANCEL=TRUE code in the form. Good idea though, made me run back in and check!! <smile>

My list box isn't multi select, but it is slaved to a text box directly underneath - for example, if you are searching for a last name, when you type &quot;S&quot; in the text box, the list box above immediately jumps to last names starting with &quot;S&quot;, then when you type &quot;M&quot;, the list box jumps to &quot;SM&quot;, etc...

Hmmm... I will try enabling &quot;multi select&quot; in the list box though, and see if that does anything...

I have used this EXACT code in another program and it worked. Why fail now??? <frustrated>

Thanks again guys for the great food for thought!

A.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top