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

2501 Error

Status
Not open for further replies.

Joshua61679

Technical User
Dec 28, 2001
36
US
I'm using this code:

Private Sub Command14_Click()
Dim strCased As String
Dim strSheet As String
Dim strField As String
Dim strCounty As String
Dim strState As String
Dim strDirections As String
Dim strLocationComments As String

strSheet = Me!Sheet
strField = Me!Field
strCounty = Me!County
strState = Me!State
strDirections = Me!Directions
strLocationComments = Me!LocationComments
strCased = " Sheet = '" & strSheet & "'"

Call DoCmd.OpenForm("Cased", , , strCased, acFormEdit)
Call DoCmd.Close(, "Directions")

Me!Field = strField
Me!County = strCounty
Me!State = strState
Me!Directions = strDirections
Me!LocationComments = strLocationComments

End Sub

But I'm getting a 2501 Error on the command to open "Cased". Did I do something wrong?
 
Remove 'Call' from the front of the DoCmd.

Run this in the immediate window to find out the error description. They are important to pass along.
?Error(2501)

-------------------------------------
scking@arinc.com
Try to resolve problems independently
Then seek help among peers or experts
But TEST recommended solutions
-------------------------------------
 
Josh:

I haven't yet detected an error in the code leading up to and including the Call DoCmd.OpenForm("Cased", , , strCased, acFormEdit) line. (P.S. Your construction using the Call statement will work. If you don't use the Call statement, then you wouldn't use the parentheses enclosing the arguments.)

However, I'm a bit confused by the following statement, Call DoCmd.Close(, "Directions"). If "Directions" is the name of a form, then you need to use acForm before the comma. According to the help, if the first argument is blank, then the second must also be blank.

Now if "Directions" is the name of the form from which you are running this code, any code following it, will not execute.

I don't think any of this will solve your problem directly, since I've tried to recreate your error, and was unsuccessful. No matter how I structured the DoCmd.OpenForm statement, my form still opened.

HTH,

Vic
 
Access message for 2501 is: ErrorString
"The | 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 the dialog box that asks if you want to save the changes you made to the form.@@1@@1" In this instance Access cancelled the DoCmd, not the user.

There is something about your DoCmd statement that Access doesn't like. Try displaying your 'strCased' that you built in a messagebox - right before your DoCmd open put strCased into a message box (e.g. msgbox "strCased = " & strCased and see what you are building - maybe your string is incorrect.
 
This can all be handled easily if you use the debugger and use error trapping, as you really should. NO code should be expected to operate perfectly every time. Integrate the following error handling code and set a breakpoint in the error handler where you want to inspect the error with the debugger. After the code traps from the debugger set the cursor on 'Resume' and click Ctrl+F9 and then F8 and the processing will move to the error line. Then, in the immediate window experiment with different DoCmd commands until it works. I assume the 'Sheet' field of the table that 'Cased' is bound to is a text field rather than numeric.

Call DoCmd.OpenForm("Cased", , , strCased, acFormEdit)
Formname = Cased
View = Null
Filter = Null
Where = ResultOf " Sheet = '" & strSheet & "'"
DataMode = acFormEdit
WindowMode = Null
OpenArgs = Null

---------------------------------
On Error GoTo HandleErr

' Body of code

Exit_Proc:
Exit Sub

HandleErr:
Select Case Err.Number
Case 2501
' This will ignore the 2501 error and proceed
' processing the 'Next' line of code.
Resume Next
Case Else
MsgBox Err.Number & ", " & Err.Description
GoTo Exit_Proc
End Select
Resume

End Sub -------------------------------------
scking@arinc.com
Try to resolve problems independently
Then seek help among peers or experts
But TEST recommended solutions
-------------------------------------
 
Thanks everyone for the help. I finally realized the problem was just that I needed to take out the 's in the strCased line. Then I did need to add acForm to the subsequent close command. Its always the stupid little stuff. Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top