Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
VBA Code Runtime Error
Amir Ouranus 
      
2 months ago
Hello,
I have a database that keeps track of employees, and in the database there is a field that tracks if they are Active, Terminated, and ect...
Originally I named the field "Active" not knowing that "Active" is a Reserved word. So, I changed the field "IsActive". However, now I am having Runtime Errors with my VBA code.
Amir Ouranus OP  @Reply  
      
2 months ago
Option Compare Database
Private Sub ApplyCombinedFilter(ByVal NewCriteria As String)

    Dim CurrentFilter As String
    Dim CombinedFilter As String
    
    
    ' Get the current filter string (if any)
    CurrentFilter = Me.Filter
    
    ' Check if a filter is already applied
    If CurrentFilter <> "" Then
        ' Combine the existing filter with the new criteria using "AND"
        ' Ensure a space is present before appending
        CombinedFilter = CurrentFilter & " AND " & NewCriteria
    Else
        ' If no filter exists, the new criteria is the entire filter
        CombinedFilter = NewCriteria
    End If
    
    ' Apply the combined filter to the form
    Me.Filter = CombinedFilter
    Me.FilterOn = True
    
End Sub

Private Sub FilterActive_Button_Click()

    ' Ensure the new criteria is a valid SQL WHERE clause fragment
    ' String values need single quotes: ' '
    
    Call ApplyCombinedFilter("[IsActive] = '1'")

End Sub
Amir Ouranus OP  @Reply  
      
2 months ago
The error is happening on the line:

Me.Filter = CombinedFilter

Any help would be greatly appreciated.
Kevin Robertson  @Reply  
          
2 months ago
What is the error?
Amir Ouranus OP  @Reply  
      
2 months ago
Run-Time Error "3709":
The search key was not found in any record.
Kevin Robertson  @Reply  
          
2 months ago
IsActive is a Boolean value and should not be enclosed in quotes.

Call ApplyCombinedFilter("[IsActive] = True")

or

Call ApplyCombinedFilter("[IsActive] = 1")
Amir Ouranus OP  @Reply  
      
2 months ago
By the wa; the field that was called "Active" and now has been renamed "IsActive", is a Combo Box.  I have follow Richard class instructions to create a separate Table that stores the different employee’s status; Active, Terminated, Inactive (Disability), and Transferred. The Table is called UserStatus-Table.
The ComboBox gets it's data from that Table.
Kevin Robertson  @Reply  
          
2 months ago
If it is a ComboBox you will need to access the Column property.

IsActive.Column(1)
Amir Ouranus OP  @Reply  
      
2 months ago
Now I'm getting:

Compile Error.
Syntax Error

On this line:

Private Sub FilterActive_Button_Click()
Amir Ouranus OP  @Reply  
      
2 months ago
And the last line is in Red:

Call ApplyCombinedFilter IsActive.Column(1)
Kevin Robertson  @Reply  
          
2 months ago
ApplyCombinedFilter "IsActive.Column(1) = 1"
Amir Ouranus OP  @Reply  
      
2 months ago
Back to this error message:

Run-Time Error "3709":
The search key was not found in any record.

And this line highlighted:

Me.Filter = CombinedFilter
John Williams  @Reply  
     
2 months ago
Amir You should be looking for the text of the combo box, not a True/False indication.  In your example, only "Active" status would be the word "Active" any of the other status values would be an inactive status.

ApplyCombinedFilter "IsActive.Column(1) = " & "Terminated"

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/20/2026 10:06:04 PM. PLT: 1s