Error 2501

A

Aleks

Some body help, please.
After this command (DoCmd.OpenForm
FormName:="frmRecepturyProd", WhereCondition:=gstrWhereID)
appear error '2501' with:'action openform was canceled'.
It's look like Access could't apply filter.
I try def. filter and use method:
OpenForm "frm....","","Filter","",....., but :(
Some times appear error, that Access could't find
form 'frm...'.
Whole code VB is:
Private Sub cmdSome_Click()
Dim strWhere As String, varItem As Variant
If Me!lstBName.ItemsSelected.Count = 0 Then Exit Sub
For Each varItem In Me!lstBName.ItemsSelected
strWhere = strWhere & Chr$(34) & Me!lstBName.Column(0,
varItem) & Chr$(34) & ","
Next varItem
strWhere = Left$(strWhere, Len(strWhere) - 1)
gstrWhereID = "[IDReceptury] IN (" & strWhere & ")"
DoCmd.OpenForm FormName:="frmRecepturyProd",
WhereCondition:=gstrWhereID
DoCmd.Close acForm, Me.Name
End Sub

P.S lstBName - list box
 
W

Wayne Morgan

Do you have any code in the OnOpen event for frmRecepturyProd that Cancels the open? If
so, you just need to trap the error in your calling code below.

Private Sub cmdSome_Click()
On Error GoTo HandleError
Dim strWhere As String, varItem As Variant
If Me!lstBName.ItemsSelected.Count = 0 Then Exit Sub
For Each varItem In Me!lstBName.ItemsSelected
strWhere = strWhere & Chr$(34) & Me!lstBName.Column(0,varItem) & Chr$(34) & ","
Next varItem
strWhere = Left$(strWhere, Len(strWhere) - 1)
gstrWhereID = "[IDReceptury] IN (" & strWhere & ")"
DoCmd.OpenForm FormName:="frmRecepturyProd", WhereCondition:=gstrWhereID
DoCmd.Close acForm, Me.Name
CleanUp:
Exit Sub
HandleError:
If Err.Number = 2501 Then Resume Next
MsgBox Err.Number & vbCrLf & Err.Description, , "Error"
Resume CleanUp
End Sub
 
G

Guest

No I have't any code in OnOpen. I try trap the error as
You said, but nothing. Maybe I didn't wrote about
Parameter Value dialog box (for gstrWhereID)after starting
opening form. It doesn't meter what you write, because
form apply filter and show always 1'st record. If you
canceled dialog box, then eppear error 2501 :(
-----Original Message-----
Do you have any code in the OnOpen event for
frmRecepturyProd that Cancels the open? If
so, you just need to trap the error in your calling code below.

Private Sub cmdSome_Click()
On Error GoTo HandleError
Dim strWhere As String, varItem As Variant
If Me!lstBName.ItemsSelected.Count = 0 Then Exit Sub
For Each varItem In Me!lstBName.ItemsSelected
strWhere = strWhere & Chr$(34) & Me!lstBName.Column (0,varItem) & Chr$(34) & ","
Next varItem
strWhere = Left$(strWhere, Len(strWhere) - 1)
gstrWhereID = "[IDReceptury] IN (" & strWhere & ")"
DoCmd.OpenForm FormName:="frmRecepturyProd", WhereCondition:=gstrWhereID
DoCmd.Close acForm, Me.Name
CleanUp:
Exit Sub
HandleError:
If Err.Number = 2501 Then Resume Next
MsgBox Err.Number & vbCrLf & Err.Description, , "Error"
Resume CleanUp
End Sub

--
Wayne Morgan
Microsoft Access MVP


Aleks said:
Some body help, please.
After this command (DoCmd.OpenForm
FormName:="frmRecepturyProd", WhereCondition:=gstrWhereID)
appear error '2501' with:'action openform was canceled'.
It's look like Access could't apply filter.
I try def. filter and use method:
OpenForm "frm....","","Filter","",....., but :(
Some times appear error, that Access could't find
form 'frm...'.
Whole code VB is:
Private Sub cmdSome_Click()
Dim strWhere As String, varItem As Variant
If Me!lstBName.ItemsSelected.Count = 0 Then Exit Sub
For Each varItem In Me!lstBName.ItemsSelected
strWhere = strWhere & Chr$(34) & Me!lstBName.Column(0,
varItem) & Chr$(34) & ","
Next varItem
strWhere = Left$(strWhere, Len(strWhere) - 1)
gstrWhereID = "[IDReceptury] IN (" & strWhere & ")"
DoCmd.OpenForm FormName:="frmRecepturyProd",
WhereCondition:=gstrWhereID
DoCmd.Close acForm, Me.Name
End Sub

P.S lstBName - list box


.
 
W

Wayne Morgan

I would expect a different error, but are there any times that the value
being retrieved from the combo box is Null? What is the data type of column
0 from the combo box?

Wayne Morgan
Microsoft Access MVP
 
G

Guest

It's Autonumber. When I use cmd FormName:= and
Condition:=, then eppear Parameter Value dialog box, but
if I use DoCmd OpenForm "frm.....",,,gstrWhereID then
eppear only error 2501
 
G

Guest

One more thing (maybe it is important) code in openig form
is:
-------------------
Private Sub Form_ApplyFilter(Cancel As Integer, ApplyType
As Integer)
gstrWhereID = Me.Filter
If IsNothing(Me.Filter) Or ApplyType =
acShowAllRecords Then
gstrWhereID = ""
End If
End Sub
------------------------
Private Sub Form_Filter(Cancel As Integer, FilterType As
Integer)
Me.Filter = ""
gstrWhereID = ""
End Sub
 
W

Wayne Morgan

In the ApplyFilter event, I looked but I don't see IsNothing as a legal function. What is
it supposed to be?

Also, is gstrWhereID DIMed as a global variable? If not, then I don't see where changing
its value is doing anything because you immediately exit the procedure after doing so,
although this won't cause an error.

You say that the field you are using to put together the IN part of your WHERE clause is
an autonumber field, yet you are putting quotes around the values (Chr(34)). I tried this
to see what would happen and received an error when I tried to apply the filter. Since
these are numbers, they shouldn't need quotes. When I tried it without the quotes, the
filter worked.
 
A

Aleks

Yes you right, I made code without chr34 and everthing
work. Thank You very much for your help and see You at
newsgroups :)
-----Original Message-----
In the ApplyFilter event, I looked but I don't see
IsNothing as a legal function. What is
it supposed to be?

Also, is gstrWhereID DIMed as a global variable? If not,
then I don't see where changing
its value is doing anything because you immediately exit the procedure after doing so,
although this won't cause an error.

You say that the field you are using to put together the
IN part of your WHERE clause is
an autonumber field, yet you are putting quotes around
the values (Chr(34)). I tried this
to see what would happen and received an error when I
tried to apply the filter. Since
these are numbers, they shouldn't need quotes. When I
tried it without the quotes, the
 

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