473,406 Members | 2,619 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,406 software developers and data experts.

Apply Filter as Variable

Hello,
I'm very new to VBA programming, so this is my first attempt at creating a interactive (with forms) database. I have a database of a few thousand records, containing first name, last name, city, state, and phone numbers.

What I'd like to do is have the user enter the First Name into a text box and then the FIRSTNAME column is filtered by that value, thereby searching the database for all records with that first name.

Now the first time I open the database and click the button that triggers the code it pops up a window that says "parameter value?" for the name I've entered into the text box.

Any ideas? Thank you so much.

Here is the code I have:

Private Sub Find_Click()
On Error GoTo Err_Find_Click
Dim strName As String
strName = ""
Me.first.SetFocus
strName = first.Text
DoCmd.ApplyFilter , "FIRSTNAME = " & strName
Me.first.SetFocus

Exit_Find_Click:
Exit Sub

Err_Find_Click:
MsgBox Err.Description
Resume Exit_Find_Click

End Sub

*Note: "first" is the name of the text box
Mar 29 '10 #1
3 6443
ADezii
8,834 Expert 8TB
Expand|Select|Wrap|Line Numbers
  1. Dim varFirst As Variant    'In case of NULLs
  2.  
  3. varFirst = Me![First]
  4.  
  5. If Not IsNull(Me![First]) Then      'Is a Value present?
  6.   'Do any Record(s) with that First Name actually exist? Be sure
  7.   'to substitute your own Table and Field Name below
  8.   If DCount("*", "Employees", "[FirstName] = '" & varFirst & "'") > 0 Then
  9.     DoCmd.ApplyFilter , "FIRSTNAME = '" & varFirst & "'"
  10.   Else
  11.     MsgBox "No Records with a First Name of " & varFirst & " exist in the Database", _
  12.             vbExclamation, "No Matching Records Found"
  13.   End If
  14. End If
Mar 29 '10 #2
ADezii,
Thanks so much! It worked perfectly! great to have the help :)
Mar 29 '10 #3
ADezii
8,834 Expert 8TB
You are quite welcome.
Mar 29 '10 #4

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

Similar topics

9
by: Robin Cull | last post by:
Imagine I have a dict looking something like this: myDict = {"key 1": , "key 2": , "key 3": , "key 4": } That is, a set of keys which have a variable length list of associated values after...
2
by: Themis Parintas ste kardias | last post by:
How can i apply a filter on a form on a field with text when i select from a combo box
16
by: Nhmiller | last post by:
I already have a report designed under Reports. When I use filtering in Forms or Tables, I see no way to select that filtered list when I am in Reports, and there appears to be no way to do the...
3
by: mattscho | last post by:
Hi All, Trying to create a set of 3 buttons in a form that have the same effect as the "Filter by Form", "Apply Filter" and "Remove Filter" Buttons on the access toolbar. Help would be muchly...
1
by: mattscho | last post by:
Re: Filter By From, Apply Filter, Remove Filter Buttons in a Form. -------------------------------------------------------------------------------- Hi All, Trying to create a set of 3 buttons in...
3
by: Gord | last post by:
I'm trying to filter a report with a date in VB code. If I type an actual date bracketed with the pound symbol (i.e. #3-Jul-08#) I can get the filter to work. I can't seem to get it to work by...
1
by: eHaak | last post by:
A couple years ago, I built a database in MS Access 2003. I built the form using macros in some of the command buttons, and now I’m trying to eliminate the macros and just use visual basic code. ...
3
by: dbdb | last post by:
hi guys need your suggestion how can i apply filter for my date variable data type i have a form name transaction and i have a text box on it named : start and finish i need to apply...
10
by: dbdb | last post by:
Hi, i create a chart in ms access based on my query, then i want my chart when is it open is only show value based on my criteria. i'll try to used it in the properties apply filter using the...
5
by: phill86 | last post by:
Hi, I have a form that I have applied a filter to by using combo boxes which works fine. Is there a way to apply that filter to the forms underlying query Here is the code that I use to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.