By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,477 Members | 1,384 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,477 IT Pros & Developers. It's quick & easy.

FindFirst Problem

Alireza355
P: 86
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
Share this Question
Share on Google+
4 Replies


ADezii
Expert 5K+
P: 8,679
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
Expert 100+
P: 200
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

Alireza355
P: 86
Thank you Adezii,

it works perfectly...
May 10 '09 #4

ADezii
Expert 5K+
P: 8,679
@Alireza355
You are quite welcome.
May 10 '09 #5

Post your reply

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