Query coding question

G

Guest

I have the following code attached to a command button on my DAP that I use
to return records in a recordset. The problem is, if the user doesn't type in
the "CompanyName" value exactly as it is in the database, I get an error
saying the company doesn't exist. Is there any way to alter the code in order
to accomplish the same thing as "Like & etc..." in a Parameter query? Any
help would be great.

<SCRIPT language=vbscript event=onclick for=Command0>
<!--
' Clone the recordset
Dim rs
Set rs = MSODSC.DataPages(0).Recordset.Clone

On error resume next
' This is the command line for the search string.
rs.find "CompanyName= '" & Cstr(InputBox("Please enter the company_
information you wish 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 record of company in database",,"Done_ Searching"
Exit Sub
End if

MSODSC.DataPages(0).Recordset.Bookmark = rs.Bookmark
-->
</SCRIPT>
 
G

Guest

This sidesteps your question a bit, but could you use a combo box instead of
a text box? You could build the combo box row source from the table that
contains the company names. If you set both Auto Expand and Limit to List
(in the combo box properties) to Yes you may find that answers your needs.
 

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