473,386 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Search routine for a data access page.

This loop searches through all the fields in a table. I get a problem when executing it says "expected end of statement"; line 24 on here. Syntax problem? I don't see it.

Expand|Select|Wrap|Line Numbers
  1. 'code from MSDN for a simple search function.
  2. 'http://support.microsoft.com/kb/271728
  3.  
  4. dim i           'Counter variable
  5. dim rs          'ADO recordset object
  6. dim fld         'ADO field object
  7. dim FieldCount  'Number of fields in the recordset
  8.  
  9. FieldCount = MSODSC.DefaultRecordset.Fields.Count
  10.  
  11. 'This will return the default recordset on the page
  12. 'in this case, the Customers table.
  13. set rs = MSODSC.DefaultRecordset
  14.  
  15. for i = 0 to FieldCount - 1
  16.     'get a field object
  17.     set fld = rs.Fields(i)
  18.  
  19.     '0 = Skip no records
  20.     '1 = Search forward
  21.     '1 = Start with the first record
  22.  
  23. 'the next line is where the debugger stops on the error.
  24.     rs.Find fld.name & " = '" & txtSearch.value & "'", 0, 1, 1 
  25.  
  26.     'Check for EOF.  If  at EOF but have not exhausted
  27.     'all the fields, then reset to the first position in the 
  28.     'recordset.  Otherwise, if a match was found, exit the loop.
  29.     if rs.EOF then 
  30.         rs.MoveFirst
  31.     else
  32.         exit for
  33.     end if
  34. next
  35.  
  36. 'Clean up.
  37. set fld = nothing
  38. set rs = nothing
Sep 24 '07 #1
5 3216
This is how I got it to work. There are quite a few questions about this floating around on here so I will try to post the link on there discussions.

FOR A DATA ACCESS PAGE! Straight from microsoft.
This will search a single Integer Field for an Integer given by the user and display the corresponding record set. No wildcards allowed in this example.

(A string search will also work with a bit of tweaking)

In design view
1. turn off the controls wizard
2. create a command button and name it cmdSearch
3. go to Tools --> Macro --> Microsoft Script Editor
4. from the Objects and Events box select cmdSearch
5. from the Events box(to the right) select OnClick
6. this will set your cursor in the correct place to insert the following code.


Expand|Select|Wrap|Line Numbers
  1. ' Clone the recordset.
  2.  
  3. Dim rs
  4. Set rs = MSODSC.DataPages(0).Recordset.Clone
  5. On error resume next
  6.  
  7. ' This line assumes that the value you are filtering on is an integer.
  8. ' If the search value is a string, use slightly different syntax.
  9. ' For example, "Field you want to search = '" & CStr(InputBox("Please enter Whatever you want to find", "Find")) & "'" 
  10. rs.find "[yOUR fIELD HERE]=" & cLng(inputbox("Enter Something to find","Find"))
  11. ' Custom error handling.
  12. If (err.number <> 0) Then
  13.     Msgbox "Error: " & err.number & " " & err.description,,"Invalid Search"
  14.     Exit Sub
  15. End If
  16. ' Check search results for success.
  17. If (rs.bof) or (rs.eof) Then
  18.     Msgbox "No wHATEVER found",,"Search Done"
  19.     Exit Sub
  20. End If
  21. MSODSC.DataPages(0).Recordset.Bookmark = rs.Bookmark
  22. -->

Hope this helps.

James
Sep 25 '07 #2
Alright so I got it to work searching for Integers only. I thought I would try out searching for strings so I take the:
Expand|Select|Wrap|Line Numbers
  1. rs.find "[WO NUMBER]=" & cLng(inputbox("Enter a Workorder Number","Find"))
and change it to:
Expand|Select|Wrap|Line Numbers
  1. rs.find "[CUSTOMER NAME]= " & CStr(InputBox("Please enter customer to find", "Find"))&""
and it gets an error about using the wrong data type. It will find an integer (a number) if I put one into the table. I tried making a customer named 12345 and used the CStr syntax above and it works fine. It will not, however, find a string.

In the example their is an example to search a string:
Expand|Select|Wrap|Line Numbers
  1. ' If the search value is a string, use slightly different syntax.
  2. ' For example, "CustomerID = "'" & CStr(InputBox("Please enter customer to find", "Find")) & "'" 
this in itself will not work. the syntax is wrong.
Sep 26 '07 #3
This here is teh goodness.
Expand|Select|Wrap|Line Numbers
  1. rs.find "[Customer NAME] = '" & CStr(InputBox("Please enter customer to find", "Find")) & "'"
Now I'm trying to get wildcards to work. From what I've read you can change the = to LIKE.
Expand|Select|Wrap|Line Numbers
  1. rs.find "[job name] LIKE '" & CStr(InputBox("Please enter a job name to find", "Find")) & "'"
This will not return a record though. I think this will become a "How To" search for record sets for noobs before I'm done with it.
Sep 28 '07 #4
This here is teh goodness.
Expand|Select|Wrap|Line Numbers
  1. rs.find "[Customer NAME] = '" & CStr(InputBox("Please enter customer to find", "Find")) & "'"
Now I'm trying to get wildcards to work. From what I've read you can change the = to LIKE.
Expand|Select|Wrap|Line Numbers
  1. rs.find "[job name] LIKE '" & CStr(InputBox("Please enter a job name to find", "Find")) & "'"
This will not return a record though. I think this will become a "How To" search for record sets for noobs before I'm done with it.
I have somewhat of a solution for this. Change your line to the below:

rs.find "[job name] LIKE %" & CStr(InputBox("Please enter a job name to find", "Find")) & "%"

However, It only brings you to the closest record that you typed and doesnt filter the records down which would be ideal. Any thoughts of how to set it to not only find but filter?
Mar 17 '08 #5
This was very helpful for me .. I found your use of the "LIKE" statement will work for me so long as the wildcard "%" is used following the search term. . wonder if there's a way to programatically add this to the end of the search
Sep 14 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: WindAndWaves | last post by:
Hi Gurus I am keen to make a search page on a website, but I have absolutely zero experience with PHP. I am going to hire an expert, but I thought that it may pay to try it a bit first myself...
1
by: Caliangelas | last post by:
Hello, I need a routine to check for a number called CPF (just like Social Security Number in USA). I already have a validation routine for that number, but I still need to check if it exists on...
16
by: Andy_Khosravi | last post by:
I'm in a bit of a pickle. My employer, a health insurance firm, had me design a small database to track benefit issues. The intended users were technical specialists and some managers (about 90...
8
by: ignatova | last post by:
Hello, I have been using IBM Net Search Extender to perform full text searches on text columns in relational tables in DB2 without any problems until now. However it doesn't seam to function...
5
by: DFS | last post by:
This works pretty well, and it's easy, but it's not the ultimate solution. The kludgey part is it uses a hidden field to incrementally capture the keystrokes in the visible field (because executing...
1
by: grabit | last post by:
Hi Peoples i have a search page with a form field "subject" on my results page i have a paging routine . the first page lists its 10 records no trouble but when i click the "next" link i get a error...
6
by: ARC | last post by:
I'm almost ready to build an upgrade routine for a commercial app that will need to import data from an existing Access 97 back-end database to an Access 2007 back-end blank database. Ideally, it...
7
by: =?Utf-8?B?SklNLkgu?= | last post by:
How to get search engines crawl data I have a web application that uses user controls and pulls data directly from database and shows it to users in the internet. So there is not html that has the...
0
by: JamesOo | last post by:
I have the code below, but I need to make it searchable in query table, below code only allowed seach the table which in show mdb only. (i.e. have 3 table, but only can search either one only,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.