473,385 Members | 1,641 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,385 software developers and data experts.

FindFirst Problem

Alireza355
I am trying to have a search in a subform to find records that include a certain word. This word can be at any part of field.

I am having difficaulty figuring it out.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command22_Click()
  2. Dim rst As Recordset
  3. If Not IsNull(Text1) Then
  4. Set rst = [Forms]![MyForm]![MySubform].Form.RecordsetClone
  5.  
  6. rst.FindFirst "[MyField] Like """ & Me.Text1 & "*"""
  7.  
  8. If Not rst.NoMatch Then
  9. [Forms]![MyForm]![MySubform].Form.Bookmark = rst.Bookmark
  10. Else
  11.  
  12. MsgBox "Not Found!"
  13. End If
  14. End If
  15.  
  16. rst.Close
  17. Set rst = Nothing
  18.  
  19. End Sub
  20.  
But this code only searches for records that start with that certain word. if the word is in the middle of the field, it does not bookmark that record.

In a normal query, I use this:

MyField Like "*" & [forms]![Myform]![text1] & "*"


But I don't know how to do the same with FindFirst

Can anyone provide any help?????

Thanx a lot
May 9 '09 #1
4 2852
ADezii
8,834 Expert 8TB
Expand|Select|Wrap|Line Numbers
  1. Dim rst As Recordset
  2.  
  3. If IsNull(Text1) Then Exit Sub
  4.  
  5. Set rst = [Forms]![MyForm]![MySubform].Form.RecordsetClone
  6.  
  7. rst.FindFirst "[MyField] Like ""*" & Me.Text1 & "*"""
  8.  
  9. If Not rst.NoMatch Then
  10.   [Forms]![frmMain]![Child].Form.Bookmark = rst.Bookmark
  11. Else
  12.   MsgBox "Not Found!"
  13. End If
  14.  
  15. rst.Close
  16. Set rst = Nothing
  17.  
May 9 '09 #2
GazMathias
228 Expert 128KB
I usually approach this in one of two ways.

Either I delete and redeclare the querydefs on the the query behind the subform or I include { Like "*" & [Forms]![Someform]![Somefield] & "*" } in the criteria of the field being searched for the query behind the form.

I nearly always create a query for form data as it is allows you the freedom to manipulate it in this way.

Obviously which one I choose depends on the form's function but they generally both work in their respective circumstance.

Gaz.
May 9 '09 #3
Thank you Adezii,

it works perfectly...
May 10 '09 #4
ADezii
8,834 Expert 8TB
@Alireza355
You are quite welcome.
May 10 '09 #5

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

Similar topics

2
by: Prakash Wadhwani | last post by:
I have a form (continuous) with a few fields : First Name, Last Name, Policy Number, etc. In the form footer I have a combo box for LastName which has 3 TEXT fields: LastName, FirstName & Policy...
5
by: Mike | last post by:
Hi I've written a module to find the first occurrence of a record in a query (that is my forms datasource) that matches four specified criteria. No matter what I try it doesn't seem to find ...
3
by: Mark | last post by:
I get "error 3077 Syntax Error (missing operator) in expression" in this expression: Rst.FindFirst "='" & Me!NewSection & "'" when Me!NewSection contains an apostrophe. How can I write the...
5
by: Paul | last post by:
The 2 statements below work perfectly when using them individually. But when I try to concatenate them, they don't. rst.FindFirst " = " & OldQuoteNumber rst.FindFirst " Is Null" Can someone...
1
by: cnlai | last post by:
Snippets -------- Dim mydb As Database, myset As DAO.Recordset Set mydb = CurrentDb Set myset = mydb.OpenRecordset("abc") myset.FindFirst (" = 'S02'") '<< problem here Reference: MS DAO...
1
by: Mike MacSween | last post by:
rstStuAddr.MoveFirst rstStuAddr.FindFirst "CountryID = 168 AND Left(CLPostCode,4) <> 'BFPO'" CountryID and CLPostCode are names of fields in rstStuAddr It works. But doesn't look like it...
2
by: rivka.howley | last post by:
I wrote some code that creates a table with a date/time field at 15-minute intervals. Here's how I create and populate the table With tblDataTemp ..Fields.Append .CreateField("CT_ID", dbLong)...
3
by: wvhines | last post by:
Hello: I am an ambitious novice...I have a main form "frmGeneralContracting" that has a subform on it called "frmsubDeliverables" and I am trying to restrict editing if the current user's login...
25
by: Rick Collard | last post by:
Using DAO 3.6 on an Access 2002 database, I'm getting unexpected results with the FindFirst method. Here's the simple code to test: Public Sub FindIt() Dim db As Database, rs As Recordset...
13
by: ChrisD76 | last post by:
Hi, I am new to using VBA, and have been working with DAO Recordsets. I'm working on a little problem, and think that DAO Recordsets are the solution. I've been playing around with them to try and...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...

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.