Find button

  • Thread starter cboisseau via AccessMonster.com
  • Start date
C

cboisseau via AccessMonster.com

This appears to be easy for me, but for some reason I can't get my head
around it.

I have a find button that I would like to give me the results for all titles
under that publisher code.

What is wrong with this?

Private Sub Command49_Click()
FindPubCode
End Sub

Private Function FindPubCode() As String
On Error GoTo Err_commandmsgbox
Dim ENTER_PUBCODE As String
Dim ERRORPARAMETER As String
ENTER_PUBCODE = InputBox("PLEASE ENTER THE PUBCODE")
Me.FilterOn = False
Me.Filter = pubcode
Me.FilterOn = True
ERRORPARAMETER = pubcode
FindPubCode = True
Exit Function
Err_commandmsgbox:
FindPubCode = False
MsgBox "There are no results that match that criteria.", vbDefaultButton1
Me.FilterOn = False

End Function

I am getting mixed results, if any result at all.
 
D

Duane Hookom

I would expect a line of code change:
Me.Filter = "[SomeField]=""" & pubcode & """"

Also you have defined the function as returning a string but you have this
line which returns a boolean:
FindPubCode = True
 
D

Dale Fye

I think that should be:

Me.Filter = "[SomeField]=""" & ENTER_PUBCODE & """"

For the life of me, I couldn't figure out how your code was getting into the
Error handler, so I had to actually create a table and form to see for
myself. I was also trying to figure out where [PubCode] was defined, then I
realized that I had used it as a field name (assume you did too) and that
when no records were returned, setting the string (ERRORPARAMETER) equal to
NULL (no records, so no value) was what was causing the error. Neat trick.

I usually just count the number or records returned by the filter using:

me.RecordsetClone.recordcount

HTH
Dale


--
Don''t forget to rate the post if it was helpful!

Email address is not valid.
Please reply to newsgroup only.


Duane Hookom said:
I would expect a line of code change:
Me.Filter = "[SomeField]=""" & pubcode & """"

Also you have defined the function as returning a string but you have this
line which returns a boolean:
FindPubCode = True
--
Duane Hookom
Microsoft Access MVP


cboisseau via AccessMonster.com said:
This appears to be easy for me, but for some reason I can't get my head
around it.

I have a find button that I would like to give me the results for all titles
under that publisher code.

What is wrong with this?

Private Sub Command49_Click()
FindPubCode
End Sub

Private Function FindPubCode() As String
On Error GoTo Err_commandmsgbox
Dim ENTER_PUBCODE As String
Dim ERRORPARAMETER As String
ENTER_PUBCODE = InputBox("PLEASE ENTER THE PUBCODE")
Me.FilterOn = False
Me.Filter = pubcode
Me.FilterOn = True
ERRORPARAMETER = pubcode
FindPubCode = True
Exit Function
Err_commandmsgbox:
FindPubCode = False
MsgBox "There are no results that match that criteria.", vbDefaultButton1
Me.FilterOn = False

End Function

I am getting mixed results, if any result at all.
 

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