Error 2501

  • Thread starter Thread starter Alain
  • Start date Start date
A

Alain

Hi,

I need to use the Where Condition argument on the Docmd.Openform so I can
reduce to 1 entry forms in my db by applying conditions on the form instead
of having multiple same form with different query as RecordSource
I use the following:

Dim strCond as String
strCond = "[Active] = 'Yes' and [LeasedToThirdParty] = 'No'"

DoCmd.OpenForm Rst![Argument], acNormal, ,strCond

When I run the code I get the error 2501 not knowing why, can anyone let me
know what cause this to happen ?
To my understanding, the Where Condition arg is to restrick or narrow down
the amount of recordsets.
Is it possible that it narrows it down to one only instead of a few ?
If so then how can apply some criteria at the query level when I open a from
?

TIA

Alain
 
Error 2501 is Access' way of notifying your code that the OpenForm you
requested did not occur. You can use error-handling to trap and suppress
this message if you wish.

As to why it did not occur, chances are that the WhereCondition is not
correctly formed. For example, if these are yes/no fields, you don't want to
compare the value to text (in quotes), so try:
strCond = "([Active] = True) AND ([LeasedToThirdParty] = False)"
 
Thanks Allen,

for the error-handling trap, is there somewhere good documentation so I can
learn and start using it, I never felt I need it

Thanks


Allen Browne said:
Error 2501 is Access' way of notifying your code that the OpenForm you
requested did not occur. You can use error-handling to trap and suppress
this message if you wish.

As to why it did not occur, chances are that the WhereCondition is not
correctly formed. For example, if these are yes/no fields, you don't want
to compare the value to text (in quotes), so try:
strCond = "([Active] = True) AND ([LeasedToThirdParty] = False)"

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Alain said:
I need to use the Where Condition argument on the Docmd.Openform so I
can reduce to 1 entry forms in my db by applying conditions on the form
instead of having multiple same form with different query as RecordSource
I use the following:

Dim strCond as String
strCond = "[Active] = 'Yes' and [LeasedToThirdParty] = 'No'"

DoCmd.OpenForm Rst![Argument], acNormal, ,strCond

When I run the code I get the error 2501 not knowing why, can anyone let
me know what cause this to happen ?
To my understanding, the Where Condition arg is to restrick or narrow
down the amount of recordsets.
Is it possible that it narrows it down to one only instead of a few ?
If so then how can apply some criteria at the query level when I open a
from ?
 
Okay, so it sounds like you are growing to the place where you appreciate
error handling. :-)

The first part of this article:
Error Handling in VBA
at:
http://allenbrowne.com/ser-23a.html
explains the basics. (You can ignore the 2nd part about how to keep a record
of the errors for now if you wish.)

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Alain said:
Thanks Allen,

for the error-handling trap, is there somewhere good documentation so I
can learn and start using it, I never felt I need it

Thanks


Allen Browne said:
Error 2501 is Access' way of notifying your code that the OpenForm you
requested did not occur. You can use error-handling to trap and suppress
this message if you wish.

As to why it did not occur, chances are that the WhereCondition is not
correctly formed. For example, if these are yes/no fields, you don't want
to compare the value to text (in quotes), so try:
strCond = "([Active] = True) AND ([LeasedToThirdParty] = False)"


Alain said:
I need to use the Where Condition argument on the Docmd.Openform so I
can reduce to 1 entry forms in my db by applying conditions on the form
instead of having multiple same form with different query as
RecordSource
I use the following:

Dim strCond as String
strCond = "[Active] = 'Yes' and [LeasedToThirdParty] = 'No'"

DoCmd.OpenForm Rst![Argument], acNormal, ,strCond

When I run the code I get the error 2501 not knowing why, can anyone let
me know what cause this to happen ?
To my understanding, the Where Condition arg is to restrick or narrow
down the amount of recordsets.
Is it possible that it narrows it down to one only instead of a few ?
If so then how can apply some criteria at the query level when I open a
from ?
 
This a sample of code I use to trap errors when the user clicks on Add
Another Request Button.

Primary Key is DATE + AM_PM with no duplicates

If a duplicate entry is made error 3022 is generated by the system where it
is trapped and displayed in a suitable message.

If a Date or AM_PM is missing error code 3058 is generated by the system
where it is trapped and displayed in a suitable message.

For other errors the error number is displayed together with the error
message and could be used to displayed a suitable message etc.


Private Sub Add_Another_Request_Click()
On Error GoTo Err_Add_Another_Request_Click

Dim data_err As Integer
Dim Response As Integer
Dim strMsg As String

If (Me!A = False) And (Me!B = False) Then
DoCmd.CancelEvent
MsgBox ("A or B MUST be Selected")
Else
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
DoCmd.GoToRecord , , acNewRec
End If


Exit_Add_Another_Request_Click:
Exit Sub

Err_Add_Another_Request_Click:

data_err = Err.Number

Select Case data_err

Case 3022 ' duplicate entry
strMsg = "DUPLICATE ENTRY - Check Date, AM or PM "
MsgBox strMsg
Response = acDataErrContinue

Case 3058 ' missing an index value
strMsg = "Missing Field - Check Date, AM or PM "
MsgBox strMsg
Response = acDataErrContinue

Case Else
MsgBox (" add Error # " & Str(Err.Number) & " was generated by" _
& Err.Source & Chr(13) & Err.Description)
End Select

Resume Exit_Add_Another_Request_Click

End Sub
 
Fair enough.

BTW, engine-level errors (not errors triggered by code), need to be trapped
in the Error event of the form. For example, if you enter the date:
32/13/2005
Access says that's not valid for the type of field. That did not get
triggered by your code, but by the engine's inability to put the value into
the field, so Form_Error will trap those if you need to.
 
Back
Top