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

Explain vba search code

100+
P: 173
I managed to find a search example on the forum but i dont understand the following code properly........

can someone explain this to me:

Expand|Select|Wrap|Line Numbers
  1. Private Sub QuickSearch_AfterUpdate()
  2.  
  3. DoCmd.Requery
  4. Me.RecordsetClone.FindFirst "[provider] = '" & Me![QuickSearch] & "'"
  5. If Not Me.RecordsetClone.NoMatch Then
  6.    Me.Bookmark = Me.RecordsetClone.Bookmark
  7. Else
  8.    MsgBox "Could not locate [" & Me![QuickSearch] & "]"
  9. End If
  10.  
  11. End Sub
thanks
Dec 18 '06 #1
Share this Question
Share on Google+
8 Replies


missinglinq
Expert 2.5K+
P: 3,532
Private Sub QuickSearch_AfterUpdate()
'Reruns the query the form is based on
DoCmd.Requery
'Goes to a record where the field provider is the same as the value in the control QuickSearch
Me.RecordsetClone.FindFirst "[provider] = '" & Me![QuickSearch] & "'"
'If a match is found a bookmark is set to the record
If Not Me.RecordsetClone.NoMatch Then
Me.Bookmark = Me.RecordsetClone.Bookmark
'If no match is found a messagebox popsup to report the failure
Else
MsgBox "Could not locate [" & Me![QuickSearch] & "]"
End If

End Sub

If a match is found, the bookmark will cause the appropriate record to be displayed.
Dec 18 '06 #2

100+
P: 173
thanks for that...........

what are the errors that you can get when you use this code?

im using this code for my search form but im having problems with the following line:
Expand|Select|Wrap|Line Numbers
  1. Me.RecordsetClone.FindFirst "[provider] = '" & Me![QuickSearch] & "'"
why do u think that is?
Dec 18 '06 #3

missinglinq
Expert 2.5K+
P: 3,532
What problems/error codes are you getting? Is the field you're searching on named provider? Is the text box you're entering your search string in named QuickSearch! Otherwise, the code won't work!
Dec 19 '06 #4

MMcCarthy
Expert Mod 10K+
P: 14,534
thanks for that...........

what are the errors that you can get when you use this code?

im using this code for my search form but im having problems with the following line:
Expand|Select|Wrap|Line Numbers
  1. Me.RecordsetClone.FindFirst "[provider] = '" & Me![QuickSearch] & "'"
why do u think that is?
Me.RecordsetClone gets all records currently bound to a form and puts them in a recordset. If your search form is not bound to a table or query it won't return anything.

Mary
Dec 19 '06 #5

100+
P: 173
Me.RecordsetClone gets all records currently bound to a form and puts them in a recordset. If your search form is not bound to a table or query it won't return anything.

Mary

Ok,
the error that i am getting is the following:

Run-time error '7951';

You entered an expression that has an invalid reference to the RecordsetClone property.


and it takes me to the code part which i mentioned in my previous post.

y is that?
Dec 19 '06 #6

MMcCarthy
Expert Mod 10K+
P: 14,534
Ok,
the error that i am getting is the following:

Run-time error '7951';

You entered an expression that has an invalid reference to the RecordsetClone property.


and it takes me to the code part which i mentioned in my previous post.

y is that?
Is your form bound to a table or query?
Dec 19 '06 #7

100+
P: 173
Is your form bound to a table or query?
Its bound to a query qry_all_details.

what i have is a textbox that has another text box underneath it....

in the first text box i enter the providers name and it lists all the details in the second text box (in order of the provider - just showing the provider i searched for)

if i dont type in anything in the first textbox..... it just shows a list of all details in the second textbox(from qry_all_details)..........

what i want to do also is, by selecting the provider in the second textbox, i want it to bring up all the details in a form style on the same page(possibly below the two textboxes)....... how do i do it???

but firstly how do i rectify the error im getting?
Dec 19 '06 #8

NeoPa
Expert Mod 15k+
P: 31,616
Try
Expand|Select|Wrap|Line Numbers
  1. Debug.Print "[provider] = '" & Me![QuickSearch] & "'"
before your line that searches for it and post the results (Copy from immediate pane - Ctrl-G to get there).
Dec 19 '06 #9

Post your reply

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