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

Findnext and FindRecord problem

26
Well, in need to find a record using a command button so I set up a FindRecord in a macro. Now the person wants to be able to find all the records that meet the last name criterian so I thought I would use FindNext but as I found out you cant do that because the focus shifts so it starts over. The help menu said to use a custom Toolbar button. But I don't know what that is and I'm not all that good at VBA programing could yous help.
thanx
Steve
Sep 13 '07 #1
7 3787
ADezii
8,834 Expert 8TB
Well, in need to find a record using a command button so I set up a FindRecord in a macro. Now the person wants to be able to find all the records that meet the last name criterian so I thought I would use FindNext but as I found out you cant do that because the focus shifts so it starts over. The help menu said to use a custom Toolbar button. But I don't know what that is and I'm not all that good at VBA programing could yous help.
thanx
Steve
You could simply set a Filter for your Form as in:
Expand|Select|Wrap|Line Numbers
  1. Me.Filter = "[LastName]='" & "Mitchell" & "'"
  2. Me.FilterOn = True
To turn off the Filter:
Expand|Select|Wrap|Line Numbers
  1. Me.FilterOn = False
Sep 14 '07 #2
BUmed
26
But this search is at the end of a form, so if some one is looking to find this persons form they would type in the last name and hit the search button. The way I have it now it can only find the first occurrence of the last name. Would this code work in this way (with a button). Thanx for your help
Sep 14 '07 #3
BUmed
26
I have been looking and it looks like it can be done with DoCmd.FindRecord but I don't know how to set this up. Any suggestions
Steve
Sep 14 '07 #4
ADezii
8,834 Expert 8TB
But this search is at the end of a form, so if some one is looking to find this persons form they would type in the last name and hit the search button. The way I have it now it can only find the first occurrence of the last name. Would this code work in this way (with a button). Thanx for your help
You can define the Filter within the Click() Event of a Command Button. Assuming the Text Box containing the Last Name to serarch for is called txtLastName, and the Field is named [Last Name], the following code will set the Filter of the Form to return all Records meeting the criteria:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command60_Click()
  2. If Not IsNull(Me![txtLastName]) Then
  3.   Me.Filter = "[Last Name]= '" & Me![txtLastName] & "'"
  4.   Me.FilterOn = True
  5. End If
  6. End Sub
Sep 14 '07 #5
BUmed
26
That is the best, you are so kind. Not to push my luck but is there a way to add a wild card to the last name. So, if I type in Kim it will give me Kimbull or Kimbell. Also you mentioned before that you can turn the filter off, do I make another button to do that or can you just click it again and turn it off.
Thanks again
Sep 14 '07 #6
ADezii
8,834 Expert 8TB
That is the best, you are so kind. Not to push my luck but is there a way to add a wild card to the last name. So, if I type in Kim it will give me Kimbull or Kimbell. Also you mentioned before that you can turn the filter off, do I make another button to do that or can you just click it again and turn it off.
Thanks again
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command60_Click()
  2. If Not IsNull(Me![txtLastName]) Then
  3.   Me.Filter = "[Last Name] Like '*" & Me![txtLastName] & "*'"
  4.   Me.FilterOn = True
  5. End If
  6. End Sub
  7.  
  8. 'If you type Kim in [txtLastName], will return Kimbull, Kimbell, McKimberly, Jakim, etc. Will match any pattern of criteria in [txtLastName] whether it exists in the beginning, middle, or end of the Last Name.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command60_Click()
  2. If Not IsNull(Me![txtLastName]) Then
  3.   Me.Filter = "[Last Name] Like '" & Me![txtLastName] & "*'"
  4.   Me.FilterOn = True
  5. End If
  6. End Sub
  7.  
  8. 'If you type Kim in [txtLastName], will return Kimbull, Kimbell, but not McKimberly, Jakim, etc. Will match any pattern of criteria in [txtLastName] that exists in the beginning of the String
Also you mentioned before that you can turn the filter off, do I make another button to do that or can you just click it again and turn it off.
You can place the following code in the Click() Event of a Command Button if you like, with a Caption similar to 'Show ALL Records':
Expand|Select|Wrap|Line Numbers
  1. Me.FilterOn = False
Sep 14 '07 #7
BUmed
26
Thanx so much. This worked like a charm.
Steve
Sep 17 '07 #8

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

Similar topics

4
by: Tom | last post by:
Wta is the code structure to put Rst.FindNext in a loop? I'm using what I show below. It works fine but my instinct says it should be in some standard loop rather than using the GoTo structure. ...
1
by: Stu Mac | last post by:
Hi I have a table with two fields Key Info 1 a 2 b 3 c
7
by: 4004 | last post by:
Where am I going wrong? I have a form which has a record for each date on which I teach. It has a subform which shows the classes that I teach that day. So I want to be able to click on a...
1
Corster
by: Corster | last post by:
I went through a great deal of hassle to figure this out for myself, but now it is complete, I would like to share it with the world! I know afew other people have had trouble with FindFirst and...
1
by: shiznaw | last post by:
How can I attach the findnext method to a spinbutton so that the control can browse through the values of a particular field? Private Sub SpinButton4_SpinUp() Dim mjr As Recordset Set mjr =...
1
by: Keith Wilby | last post by:
When I run this line of code from a command button on a form DoCmd.FindRecord "Domestic FW System", acStart, , acDown, , acCurrent I get the error "A macro set to one of the current field's...
4
by: RAG2007 | last post by:
Hi Having some problems with docmd.findrecord, getting runtime error 2162, in an adp, sql server back end. On my main form, I have a continuous view subform giving a list of subrecords within...
0
by: Ben Lahoy | last post by:
Hi! My problem is basically in a search modal window, where the user is allowed to make a selection on which option to take. After selecting an option and then giving the data to search, the...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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...

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.