Access 2003 - Error Code 2455

I

imelda1ab

I have a form that goes to a subform for searching. It works
perfectly on my computer; however, when another user opens it and
attempts to perform a search, they receive the Error Code 2455
message. When I debug, it gets stuck on "Me.book_subform.Form.Filter
= strWhereSearch" and says that book_subform cannot be found. It
isn't a rights issue, it isn't a mapping issue. What am I missing?
 
K

Klatuu

check your naming. This is an issue that often confused.
In this syntax:
Me.book_subform.Form.Filter > = strWhereSearch

book_subform is the name of the subform control on the main form, not the
name of the form being used as the subform. That is where the confusion
lies. On your main form, you have a subform control. One of its properties
is Source Object. The Source Object property contains the name of the form
that shows in the subform control.
You do not refer to the name of the form being used as the subform. That is
handled by the Form object. so the syntax is
Me.SubformControlName.Form.
 
I

imelda1ab

Thank you so much for your response. I'm an Access newbie so you'll
have to pardon if I make a statement or ask a question that would
cause a real Access user to shake their head, so you may have to walk
me through this like a toddler. My subform's name is book_subform and
the subform doesn't actually "appear" on the search form -- the form
is nothing more than 6 blanks for users to enter search terms. I
don't know what else to do but paste my form/subform info and the
code. Any time/help you can continue to offer is extremely
appreciated.

Form: Book_Search
Record source: qry_book_lookup

Subform: book_subform
Record source: qry_book_lookup

*********************************************
Private Sub Search_Results_Click()
On Error GoTo Err_Search_Results_Click

Dim strWhere As String
Dim lngLen As Long

'Author field
If Not IsNull(Me.authorselection) Then
strWhere = strWhere & "([author] Like ""*" & Me.authorselection
& "*"") AND "
End If

'Title Field
If Not IsNull(Me.Titleselection) Then
strWhere = strWhere & "([title] Like ""*" & Me.Titleselection
& "*"") AND "
End If

'Publisher field
If Not IsNull(Me.publisherselection) Then
strWhere = strWhere & "([publisher] Like ""*" &
Me.publisherselection & "*"") AND "
End If

'Abstract field
If Not IsNull(Me.abstractselection) Then
strWhere = strWhere & "([abstract] Like ""*" &
Me.abstractselection & "*"") AND "
End If

'Publication date field
If Not IsNull(Me.Pubdateselection) Then
strWhere = strWhere & "([PubDate] Like ""*" &
Me.Pubdateselection & "*"") AND "
End If

'Descriptor field
If Not IsNull(Me.descriptorsselection) Then 'Less than the next
day.
strWhere = strWhere & "([descriptors] Like ""*" &
Me.descriptorsselection & "*"") AND "
End If

lngLen = Len(strWhere) - 5
If lngLen <= 0 Then
Cancel = True

MsgBox "In order to perform a search, you must enter values in
one or more search fields.", vbInformation, "No Criteria Entered"
Else
strWhere = Left$(strWhere, lngLen)

'For debugging, remove the leading quote on the next line.
Prints to Immediate Window (Ctrl+G).
'Debug.Print strWhere

'Apply the string as the form's Filter.
'This is where I am getting hung up on everyone else's
computer.

Me.book_subform.Form.Filter = strWhere
Me.book_subform.Form.FilterOn = True

'Me.Filter = strWhere
'Me.FilterOn = True
'DoCmd.OpenForm "book_subform"
DoCmd.ApplyFilter "book_subform", Me.Filter

End If

DoCmd.DoMenuItem acFormBar, acRecordsMenu, 2, , acMenuVer70

Exit_Search_Results_Click:
Exit Sub
Err_Search_Results_Click:
MsgBox Err.Description
Resume Exit_Search_Results_Click

End Sub


**************************************************
Clears the search criteria from the form
Private Sub Clear_Form_Click()
On Error GoTo Err_Clear_Form_Click

'Me.FilterOn = False
Me.book_subform.Form.FilterOn = False
Me.authorselection.Value = Null
Me.Titleselection.Value = Null
Me.publisherselection.Value = Null
Me.PubDate.Value = Null
Me.abstractselection.Value = Null
Me.descriptorsselection.Value = Null
Me.searchallselection.Value = Null

Exit_Clear_Form_Click:
Exit Sub

Err_Clear_Form_Click:
MsgBox Err.Description
Resume Exit_Clear_Form_Click
End Sub
 
K

Klatuu

The basic problem is you are trying to set filters on a form that is not open

'Me.Filter = strWhere
'Me.FilterOn = True
'DoCmd.OpenForm "book_subform"

You could use the Where argument of the Openform method to do what you are
trying to do:

Docmd.OpenForm "book_subform", , ,strWhere

Also, here is a better way to build your where string:

Private Function AddAdd(strWhereString) As String
If Len(strWhereString) > 0 Then
strWhereString = strWhereString & " AND "
End If
AddAdd = strWhereString
End Function

Private Sub Search_Results_Click()
On Error GoTo Err_Search_Results_Click

Dim strWhere As String
Dim lngLen As Long

'Author field
If Not IsNull(Me.authorselection) Then
strWhere = "([author] Like ""*" & Me.authorselection
& "*"")"
End If

'Title Field
If Not IsNull(Me.Titleselection) Then
strWhere = AddAnd(strWhere)
strWhere = strWhere & "([title] Like ""*" & Me.Titleselection
& "*"")"
End If

'Publisher field
If Not IsNull(Me.publisherselection) Then
strWhere = AddAnd(strWhere)
strWhere = strWhere & "([publisher] Like ""*" &
Me.publisherselection & "*"")"
End If

'Abstract field
If Not IsNull(Me.abstractselection) Then
strWhere = AddAnd(strWhere)
strWhere = strWhere & "([abstract] Like ""*" &
Me.abstractselection & "*"")"
End If

'Publication date field
If Not IsNull(Me.Pubdateselection) Then
strWhere = AddAnd(strWhere)
strWhere = strWhere & "([PubDate] Like ""*" &
Me.Pubdateselection & "*"")"
End If

'Descriptor field
If Not IsNull(Me.descriptorsselection) Then 'Less than the next
day.
strWhere = AddAnd(strWhere)
strWhere = strWhere & "([descriptors] Like ""*" &
Me.descriptorsselection & "*"")"
End If

If Len strWhere = 0 Then
'You had a Cancel = True here, but this is not a procedure that can be
canceled
MsgBox "In order to perform a search, you must enter values in
one or more search fields.", vbInformation, "No Criteria Entered"

'DoCmd.OpenForm "book_subform", , , strWhere
End If

' DoCmd.DoMenuItem acFormBar, acRecordsMenu, 2, , acMenuVer70

I don't know what this line does. DoMenuItem as an obsolete command and is
only supported for backward compatibility.

Exit_Search_Results_Click:
Exit Sub
Err_Search_Results_Click:
MsgBox Err.Description
Resume Exit_Search_Results_Click

End Sub



--
Dave Hargis, Microsoft Access MVP


Thank you so much for your response. I'm an Access newbie so you'll
have to pardon if I make a statement or ask a question that would
cause a real Access user to shake their head, so you may have to walk
me through this like a toddler. My subform's name is book_subform and
the subform doesn't actually "appear" on the search form -- the form
is nothing more than 6 blanks for users to enter search terms. I
don't know what else to do but paste my form/subform info and the
code. Any time/help you can continue to offer is extremely
appreciated.

Form: Book_Search
Record source: qry_book_lookup

Subform: book_subform
Record source: qry_book_lookup

*********************************************
Private Sub Search_Results_Click()
On Error GoTo Err_Search_Results_Click

Dim strWhere As String
Dim lngLen As Long

'Author field
If Not IsNull(Me.authorselection) Then
strWhere = strWhere & "([author] Like ""*" & Me.authorselection
& "*"") AND "
End If

'Title Field
If Not IsNull(Me.Titleselection) Then
strWhere = strWhere & "([title] Like ""*" & Me.Titleselection
& "*"") AND "
End If

'Publisher field
If Not IsNull(Me.publisherselection) Then
strWhere = strWhere & "([publisher] Like ""*" &
Me.publisherselection & "*"") AND "
End If

'Abstract field
If Not IsNull(Me.abstractselection) Then
strWhere = strWhere & "([abstract] Like ""*" &
Me.abstractselection & "*"") AND "
End If

'Publication date field
If Not IsNull(Me.Pubdateselection) Then
strWhere = strWhere & "([PubDate] Like ""*" &
Me.Pubdateselection & "*"") AND "
End If

'Descriptor field
If Not IsNull(Me.descriptorsselection) Then 'Less than the next
day.
strWhere = strWhere & "([descriptors] Like ""*" &
Me.descriptorsselection & "*"") AND "
End If

lngLen = Len(strWhere) - 5
If lngLen <= 0 Then
Cancel = True

MsgBox "In order to perform a search, you must enter values in
one or more search fields.", vbInformation, "No Criteria Entered"
Else
strWhere = Left$(strWhere, lngLen)

'For debugging, remove the leading quote on the next line.
Prints to Immediate Window (Ctrl+G).
'Debug.Print strWhere

'Apply the string as the form's Filter.
'This is where I am getting hung up on everyone else's
computer.

Me.book_subform.Form.Filter = strWhere
Me.book_subform.Form.FilterOn = True

'Me.Filter = strWhere
'Me.FilterOn = True
'DoCmd.OpenForm "book_subform"
DoCmd.ApplyFilter "book_subform", Me.Filter

End If

DoCmd.DoMenuItem acFormBar, acRecordsMenu, 2, , acMenuVer70

Exit_Search_Results_Click:
Exit Sub
Err_Search_Results_Click:
MsgBox Err.Description
Resume Exit_Search_Results_Click

End Sub


**************************************************
Clears the search criteria from the form
Private Sub Clear_Form_Click()
On Error GoTo Err_Clear_Form_Click

'Me.FilterOn = False
Me.book_subform.Form.FilterOn = False
Me.authorselection.Value = Null
Me.Titleselection.Value = Null
Me.publisherselection.Value = Null
Me.PubDate.Value = Null
Me.abstractselection.Value = Null
Me.descriptorsselection.Value = Null
Me.searchallselection.Value = Null

Exit_Clear_Form_Click:
Exit Sub

Err_Clear_Form_Click:
MsgBox Err.Description
Resume Exit_Clear_Form_Click
End Sub


check your naming. This is an issue that often confused.
In this syntax:
Me.book_subform.Form.Filter > = strWhereSearch

book_subform is the name of the subform control on the main form, not the
name of the form being used as the subform. That is where the confusion
lies. On your main form, you have a subform control. One of its properties
is Source Object. The Source Object property contains the name of the form
that shows in the subform control.
You do not refer to the name of the form being used as the subform. That is
handled by the Form object. so the syntax is
Me.SubformControlName.Form.
--
Dave Hargis, Microsoft Access MVP





- Show quoted text -
 
I

imelda1ab

The basic problem is you are trying to set filters on a form that is not open

'Me.Filter = strWhere
'Me.FilterOn = True
'DoCmd.OpenForm "book_subform"

You could use the Where argument of the Openform method to do what you are
trying to do:

Docmd.OpenForm "book_subform", , ,strWhere

Also, here is a better way to build your where string:

Private Function AddAdd(strWhereString) As String
If Len(strWhereString) > 0 Then
strWhereString = strWhereString & " AND "
End If
AddAdd = strWhereString
End Function

Private Sub Search_Results_Click()
On Error GoTo Err_Search_Results_Click

Dim strWhere As String
Dim lngLen As Long

'Author field
If Not IsNull(Me.authorselection) Then
strWhere = "([author] Like ""*" & Me.authorselection
& "*"")"
End If

'Title Field
If Not IsNull(Me.Titleselection) Then
strWhere = AddAnd(strWhere)
strWhere = strWhere & "([title] Like ""*" & Me.Titleselection
& "*"")"
End If

'Publisher field
If Not IsNull(Me.publisherselection) Then
strWhere = AddAnd(strWhere)
strWhere = strWhere & "([publisher] Like ""*" &
Me.publisherselection & "*"")"
End If

'Abstract field
If Not IsNull(Me.abstractselection) Then
strWhere = AddAnd(strWhere)
strWhere = strWhere & "([abstract] Like ""*" &
Me.abstractselection & "*"")"
End If

'Publication date field
If Not IsNull(Me.Pubdateselection) Then
strWhere = AddAnd(strWhere)
strWhere = strWhere & "([PubDate] Like ""*" &
Me.Pubdateselection & "*"")"
End If

'Descriptor field
If Not IsNull(Me.descriptorsselection) Then 'Less than the next
day.
strWhere = AddAnd(strWhere)
strWhere = strWhere & "([descriptors] Like ""*" &
Me.descriptorsselection & "*"")"
End If

If Len strWhere = 0 Then
'You had a Cancel = True here, but this is not a procedure that can be
canceled
MsgBox "In order to perform a search, you must enter values in
one or more search fields.", vbInformation, "No Criteria Entered"

'DoCmd.OpenForm "book_subform", , , strWhere
End If

' DoCmd.DoMenuItem acFormBar, acRecordsMenu, 2, , acMenuVer70

I don't know what this line does. DoMenuItem as an obsolete command and is
only supported for backward compatibility.

Exit_Search_Results_Click:
Exit Sub
Err_Search_Results_Click:
MsgBox Err.Description
Resume Exit_Search_Results_Click

End Sub

--
Dave Hargis, Microsoft Access MVP



Thank you so much for your response. I'm an Access newbie so you'll
have to pardon if I make a statement or ask a question that would
cause a real Access user to shake their head, so you may have to walk
me through this like a toddler. My subform's name is book_subform and
the subform doesn't actually "appear" on the search form -- the form
is nothing more than 6 blanks for users to enter search terms. I
don't know what else to do but paste my form/subform info and the
code. Any time/help you can continue to offer is extremely
appreciated.
Form: Book_Search
Record source: qry_book_lookup
Subform: book_subform
Record source: qry_book_lookup
*********************************************
Private Sub Search_Results_Click()
On Error GoTo Err_Search_Results_Click
Dim strWhere As String
Dim lngLen As Long
'Author field
If Not IsNull(Me.authorselection) Then
strWhere = strWhere & "([author] Like ""*" & Me.authorselection
& "*"") AND "
End If
'Title Field
If Not IsNull(Me.Titleselection) Then
strWhere = strWhere & "([title] Like ""*" & Me.Titleselection
& "*"") AND "
End If
'Publisher field
If Not IsNull(Me.publisherselection) Then
strWhere = strWhere & "([publisher] Like ""*" &
Me.publisherselection & "*"") AND "
End If
'Abstract field
If Not IsNull(Me.abstractselection) Then
strWhere = strWhere & "([abstract] Like ""*" &
Me.abstractselection & "*"") AND "
End If
'Publication date field
If Not IsNull(Me.Pubdateselection) Then
strWhere = strWhere & "([PubDate] Like ""*" &
Me.Pubdateselection & "*"") AND "
End If
'Descriptor field
If Not IsNull(Me.descriptorsselection) Then 'Less than the next
day.
strWhere = strWhere & "([descriptors] Like ""*" &
Me.descriptorsselection & "*"") AND "
End If
lngLen = Len(strWhere) - 5
If lngLen <= 0 Then
Cancel = True
MsgBox "In order to perform a search, you must enter values in
one or more search fields.", vbInformation, "No Criteria Entered"
Else
strWhere = Left$(strWhere, lngLen)
'For debugging, remove the leading quote on the next line.
Prints to Immediate Window (Ctrl+G).
'Debug.Print strWhere
'Apply the string as the form's Filter.
'This is where I am getting hung up on everyone else's
computer.
Me.book_subform.Form.Filter = strWhere
Me.book_subform.Form.FilterOn = True
'Me.Filter = strWhere
'Me.FilterOn = True
'DoCmd.OpenForm "book_subform"
DoCmd.ApplyFilter "book_subform", Me.Filter
DoCmd.DoMenuItem acFormBar, acRecordsMenu, 2, , acMenuVer70
Exit_Search_Results_Click:
Exit Sub
Err_Search_Results_Click:
MsgBox Err.Description
Resume Exit_Search_Results_Click
**************************************************
Clears the search criteria from the form
Private Sub Clear_Form_Click()
On Error GoTo Err_Clear_Form_Click
'Me.FilterOn = False
Me.book_subform.Form.FilterOn = False
Me.authorselection.Value = Null
Me.Titleselection.Value = Null
Me.publisherselection.Value = Null
Me.PubDate.Value = Null
Me.abstractselection.Value = Null
Me.descriptorsselection.Value = Null
Me.searchallselection.Value = Null
Exit_Clear_Form_Click:
Exit Sub
Err_Clear_Form_Click:
MsgBox Err.Description
Resume Exit_Clear_Form_Click
End Sub

- Show quoted text -

You are officially now by very best friend forever. Thanks a
million!!!!!
 

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

Similar Threads


Top