Error 2501 on OpenForm in Access2003

G

Gargoyle

Having a problem with a form in Access2003.

I keep getting "Error 2501: The OpenForm action was canceled"

Two tables as follows:-

tbl_ITEM_LISTINGS
ItemID [Primary Key]
ItemListingSeq [Primary Key]
ItemListingNumber
DateListed
. . . etc . . .

tbl_TRANSACTIONS
TransactionID [Primary Key]
ItemListingNumber
. . . etc . . .

There is a One-to-One relationship between the two tables on
"ItemListingNumber".
The two tables have corresponding forms "frm_ITEM_LISTINGS" (a Continuous
Form) and "frm_TRANSACTIONS" (a Single Form).

On the "frm_ITEM_LISTINGS" there is a button alongside each detail row, which
when clicked is coded thus:-

Private Sub btnTransactions_Click()
On Error GoTo Err_btnTransactions_Click
strProcedureName = "btnTransactions_Click"
lngProcedureLoc = 100
If Nz(Me!ItemListingNumber, "") = "" Then
Call ShowWarn("Transactions only allowed on recorded listing", "Missing
Listing Number")
Exit Sub
End If
Dim stDocName As String, stLinkCriteria As String
stDocName = "frm_TRANSACTIONS"
lngProcedureLoc = 200
stLinkCriteria = "ItemListingNumber = " & Me.ItemListingNumber.Value
lngProcedureLoc = 300
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_btnTransactions_Click:
Exit Sub
Err_btnTransactions_Click:
MsgBox "Error: " & Err.Number & " - " & Err.Description & vbCrLf _
& "Object: " & conObjectName & vbCrLf _
& "Process: " & strProcedureName & vbCrLf & "Location: " &
lngProcedureLoc, vbCritical
Resume Exit_btnTransactions_Click
End Sub


When the message "Error 2501: The OpenForm action was canceled" appears,
clicking on the debug button highlights the line (from above):-
DoCmd.OpenForm stDocName, , , stLinkCriteria

I have used Debug.Print to check that the stLinkCriteria is set to a valid
value
(ItemListingNumber = 85774993 in my example, which corresponds to the
ItemListingNumber.Value of 85774993 on form "frm_ITEM_LISTINGS").

I cannot understand why this error is happening. I am using similar techniques
for other related forms which open just fine.

It's probably something blindingly obvious, but I'm now at the "wood for the
trees" state.

Can anyone help please?
 
F

fredg

Having a problem with a form in Access2003.

I keep getting "Error 2501: The OpenForm action was canceled"

Two tables as follows:-

tbl_ITEM_LISTINGS
ItemID [Primary Key]
ItemListingSeq [Primary Key]
ItemListingNumber
DateListed
. . . etc . . .

tbl_TRANSACTIONS
TransactionID [Primary Key]
ItemListingNumber
. . . etc . . .

There is a One-to-One relationship between the two tables on
"ItemListingNumber".
The two tables have corresponding forms "frm_ITEM_LISTINGS" (a Continuous
Form) and "frm_TRANSACTIONS" (a Single Form).

On the "frm_ITEM_LISTINGS" there is a button alongside each detail row, which
when clicked is coded thus:-

Private Sub btnTransactions_Click()
On Error GoTo Err_btnTransactions_Click
strProcedureName = "btnTransactions_Click"
lngProcedureLoc = 100
If Nz(Me!ItemListingNumber, "") = "" Then
Call ShowWarn("Transactions only allowed on recorded listing", "Missing
Listing Number")
Exit Sub
End If
Dim stDocName As String, stLinkCriteria As String
stDocName = "frm_TRANSACTIONS"
lngProcedureLoc = 200
stLinkCriteria = "ItemListingNumber = " & Me.ItemListingNumber.Value
lngProcedureLoc = 300
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_btnTransactions_Click:
Exit Sub
Err_btnTransactions_Click:
MsgBox "Error: " & Err.Number & " - " & Err.Description & vbCrLf _
& "Object: " & conObjectName & vbCrLf _
& "Process: " & strProcedureName & vbCrLf & "Location: " &
lngProcedureLoc, vbCritical
Resume Exit_btnTransactions_Click
End Sub

When the message "Error 2501: The OpenForm action was canceled" appears,
clicking on the debug button highlights the line (from above):-
DoCmd.OpenForm stDocName, , , stLinkCriteria

I have used Debug.Print to check that the stLinkCriteria is set to a valid
value
(ItemListingNumber = 85774993 in my example, which corresponds to the
ItemListingNumber.Value of 85774993 on form "frm_ITEM_LISTINGS").

I cannot understand why this error is happening. I am using similar techniques
for other related forms which open just fine.

It's probably something blindingly obvious, but I'm now at the "wood for the
trees" state.

Can anyone help please?

What is the datatype of the [ItemListingNumber] field.
Most likely it is Integer, in which case the value of 85774993 is too
great (an integer value is from ¡V32,768 to +32,767) and an error is
created, which cancels the opening of the report.

I would hope that the field datatype is Text (it should be, as you are
never going to be performing math functions on it).

In that case you need to surround the value with single quotes.

stLinkCriteria = "ItemListingNumber = '" & Me.ItemListingNumber & "'"

which will return "ItemListingNumber = '85774993'"

Also, you can trap the error in the event's error handling.

Err_btnTransactions_Click:
If Err = 2501 Then
Else
MsgBox "Error " ... etc...
End If
Resume Exit_btnTransactions_Click

Note: There is no need to explicitly write .Value when referring to a
field's value property.
Value is the default property.
 
G

Gargoyle

All fixed now, it was a silly syntax error, I was referring to the wrong
object.

Doh!

Thanks for replies
 

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