469,287 Members | 2,664 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,287 developers. It's quick & easy.

Explain vba search code

173 100+
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
8 8932
missinglinq
3,532 Expert 2GB
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
Beany
173 100+
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
3,532 Expert 2GB
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
14,534 Expert Mod 8TB
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
Beany
173 100+
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
14,534 Expert Mod 8TB
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
Beany
173 100+
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
32,173 Expert Mod 16PB
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.

Similar topics

2 posts views Thread by davout | last post: by
3 posts views Thread by Bruce Pullen | last post: by
3 posts views Thread by Yuri | last post: by
4 posts views Thread by moondaddy | last post: by
4 posts views Thread by Bruno Alexandre | last post: by
7 posts views Thread by RobG | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.