How do I add a character search button into a data access page?

G

Guest

I'm making a database where you have a customer's name and the customer has
certain qualities that can be displayed along side the name. The customer's
are all sorted by a four letter code. There are many names in the table, so
it would be nice to have a 'find and retrieve' funtion, so that I can type in
the customer's 4 letter code and their information pops up on the data access
page.

I've been using the following link as a starting point:
http://office.microsoft.com/en-au/assistance/HA010345491033.aspx
and it has been very helpful.
However, it seems to only work if there is a numerical value for input...as
soon as I try a character string as it suggests in the code comments, I start
to get error messages. Does anyone have any ideas how I might rectify this?
Thanks for your time.....
 
G

Guest

Hillcorp,

String values must have quotes around them. Whereever you are referring to
the value as:

MyValue

change it to:

"'" & MyValue & "'"

Hope that helps.
Sprinks
 
G

Guest

Sprinks, thanks for the advice. I think I have all my quote's where they
need to be, but perhaps not? Following is the code I'm using for the Find
button:

<SCRIPT language=vbscript event=onclick for=Find>
<!--

' Clone the recordset.

Dim rs
Set rs = MSODSC.DataPages(0).Recordset.Clone
On error resume next

' This line assumes that the value you are filtering on is an integer.
' If the search value is a string, use slightly different syntax.
' For example, "CustomerID = " & CStr(InputBox("Please enter customer to
find", "Find"))

rs.find "Find=" & CStr(InputBox("Please enter J-Code to find", "Find"))
' Custom error handling.
If (err.number <> 0) Then
Msgbox "Error: " & err.number & " " & err.description,,"Invalid Search"
Exit Sub
End If
' Check search results for success.
If (rs.bof) or (rs.eof) Then
Msgbox "No Product found",,"Search Done"
Exit Sub
End If
MSODSC.DataPages(0).Recordset.Bookmark = rs.Bookmark

-->
</SCRIPT>

any ideas from that?

Thanks again...
 
D

Douglas J. Steele

Looks as though the comment in the code is incorrect.

Try:

rs.find "Find='" & CStr(InputBox("Please enter J-Code to find", "Find")) &
"'"

Exagerated for clarity, that's

rs.find " Find= ' " & CStr(InputBox("Please enter J-Code to find", "Find"))
& " ' "

If the J-Code might have apostrophes in it, try:

rs.find "Find=""" & CStr(InputBox("Please enter J-Code to find", "Find")) &
""""

or

rs.find "Find=" & Chr$(34) & CStr(InputBox("Please enter J-Code to find",
"Find")) & Chr$(34)
 
G

Guest

Thanks for that, Doug! I have placed the "'" in the spots you recommended
and will do that from now on. I'm getting a slightly new error message now,
though, saying
the paramater is incorrect. I've tried entering the data in a number of
ways (with quotes, without, CAPS, lowercase...) and am still receiving error
messages.
I appereciate all the time and effort everyone has been offering me.
 

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