Searching a number Field

JLAZ

Registered User.
Local time
Today, 03:22
Joined
Sep 17, 2003
Messages
24
I need to search a number field in a form. I'm using a unbound text box
and the code i'm using is this

Private Sub SearchStock_AfterUpdate()
Me.RecordsetClone.FindFirst "PollIdField = '" & SearchStock & "'"
Me.Bookmark = Me.RecordsetClone.Bookmark
SearchStock = Null
End Sub

This code only works if the field is a Text field

Why, and what could I do to fix the code.

I'm a self taught access user and I don't know VB I just steel alot of it from others.
 
Strings (Text)
Me.RecordsetClone.FindFirst "PollIdField = '" & SearchStock & "'"

Numbers
Me.RecordsetClone.FindFirst "PollIdField = " & SearchStock

The single quotes tell the code that this is a String Value. You want to search a numeric value so you need to leave the quotes off.
 
JLAZ said:
I don't know VB I just steal alot of it from others.

Best way to learn...if only people (myself included) would comment their code it would be even easier to learn from.

Okay, so on to your question.

We have three ways of referencing a value using special "delimiters"

The three value types are numerical, date, and text.

For text, we need to surround it by quotation marks like this:

"Example"

For dates, we need to surround it by hash/pound marks (#) like this:

#01/01/2003#

For numerical, we don't need to surround it at all. Like this:

5


The one thing to remember is that the FindFirst method is a string so we need to write the criteria as a string but taking care that we remember the "delimiter" rules above.

i.e.

using your example above, we have the string:

Code:
"PollIdField = '" & SearchStock & "'"

This could generate errors as there could be an apostrophe in the SearchStock value.

It would be better as:

Code:
"PollIdField = """ & SearchStock & """"

although I've seen others use a public constant they've defined called QUOTE which carries the value of "" which, when used in a string, carries the value of "

But, your question was how to reference a number:

Simple:

Code:
Private Sub SearchStock_AfterUpdate() 
    Me.RecordsetClone.FindFirst "PollIdField = " & SearchStock 
    Me.Bookmark = Me.RecordsetClone.Bookmark 
    SearchStock = Null 
End Sub
 
also it is not proper to say that you steal. The proper term is Plagiarize.:D
 
Thanks Mile That worked great
Although most of what you said went straight over my head

I appreciate the help
 
Thaks Travis
Not only did I word it correctly but obviously I don't know how to spell Steal either.

:D
 
lol, didn't want to comment on the spelling so I subtly corrected it when I quoted you.. :cool:
 

Users who are viewing this thread

Back
Top Bottom