473,473 Members | 1,848 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to filter Listbox (or switch rowsource) by checkbox selection

23 New Member
I'm creating an asset/employee/everything including the kitchen sink database for my office.

Currently I'm working on formEmployee.

It contains a listbox which contains all the employees, and fields for the employee details which populate by the selection in the listbox.

The listbox (listEmployee) has a query rowsource (qryEmployees).

There is a checkbox (checkCurrent) that I want to control whether the listbox shows all the employee records or only shows the current employee records.

Ideally I'd like it to modify the query, but based on other info I've found, I'm currently using an AfterUpdate to modify the rowsource of the listbox to switch between two similar queries, qryEmployees which has all records, and qryCurrentEmployee which only has current employees (determined by a yes/no field in tblEmployees that is or is not filtered in the query.

The issue I'm having is the syntax of the If/Then statement. I'm not refering to the query correctly. See below:

Expand|Select|Wrap|Line Numbers
  1. Private Sub checkCurrent_AfterUpdate()
  2.     ' Update listEmployee RowSource based on selection in checkCurrent
  3.     ' to show all employees or only current employees
  4.     If checkCurrent = True Then
  5.     listEmployee.RowSource = qryCurrentEmployee
  6.     Else
  7.     listEmployee.RowSource = qryEmployee
  8.     End If
  9.  
  10. End Sub
  11.  
How should I refer to the queries to make this work?

And are there other suggestions for how I ought to do this better than I am?

I'm new to VBA, having squeaked past VB over ten years ago in junior college, and narrowly failed C. But my currenct position will benefit from my getting much better and more comfortable with VBA. So a final question is: What references do you prefer (websites, books, etc) for your own VBA knowledge?
May 20 '10 #1
3 6396
missinglinq
3,532 Recognized Expert Specialist
You need to place your query names in double quotes! For example:

listEmployee.RowSource = qryCurrentEmployee

needs to be

listEmployee.RowSource = "qryCurrentEmployee"

Also, be sure to double check your query names. In your post you give qryEmployees, but in your code you use qryEmployee, without the ending s.

Welcome to Bytes!

Linq ;0)>

Addendum:

BTW, being rusty in Visual Basic is actually a good thing! Despite their common origin, straight VB and Access VBA are two different languages! They share many methods and functions, but this can be tricky. Many of the functions and some Properties (such as the Text Property for Textboxes) share a common name but perform differently.

The aforementioned Text Property in straight VB refers to the value of a Textbox on a Form, and is commonly used in VB.

In Access VBA, on the other hand, the Text Property refers to the actual content of a Textbox, when that Textbox has Focus! And this is not necessarily the value held by the field bound to that Textbox.

In Access VBA, we refer to the value of a Textbox by the...are you ready for this... by the Value Property!

So, within VBA code, you can refer to the value held by a Textbox, on the current record, whether the Textbox has focus or not by

Me.TextboxName.Value

or simply

Me.TextboxName

because Value is the Default Property of a Textbox and doesn't actually have to be written out.

But you can only refer to the Text Property by

Me.TextboxName.Text

and only when it currently has the focus.
May 20 '10 #2
mbedford
23 New Member
Thank you Linq. I'd found that naming discrepancy late yesterday.

Thanks for the tips regarding differences between VB and VBA as well as the other info.

...and it works!

So when I am updating a property, I should always send the new value surrounded by quotation marks?
May 21 '10 #3
missinglinq
3,532 Recognized Expert Specialist
@mbedford
So when I am updating a property, I should always send the new value surrounded by quotation marks?
Table and Query names always require Quotation Marks. They are, after all, strings!

Glad you got things working!

Linq ;0)>
May 21 '10 #4

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

Similar topics

4
by: Nicolas Rubin | last post by:
Hi, I would transfer the result of a checkbox selection into an SQL request. Could you help me ? Many thanks in advance Nicolas
3
by: RRT | last post by:
I have an existing table which describes Streets and sections of streets between intersections: Table 1: Streets by Intersections Street Area Ann St. Main to Jackson...
2
by: (Pete Cresswell) | last post by:
Seems like I've been here before, but can't find anyting in Google. I've got two list boxes on a form. Seems to me like the inactive ListBox's selection rectangle should be something like...
1
by: Joja | last post by:
I have 3 checkboxes but the user should select just one. How to block multiple checkbox selection ? Joja
3
by: =?Utf-8?B?QmFkaXM=?= | last post by:
Hi, I have a 5 checkboxes and I would like to be able to use them as grouped radiobuttons or a checkboxlist (one selection at the time) in the client side without having to use a autopostback....
0
by: marcelo | last post by:
Could you help me out here. I need to accomplish this: I need to filter listbox items from by entering some characters to the textbox. But the problem is that items (files that are read from...
7
by: bluray | last post by:
I have been fighting with this for a while, and I know someone on this board will be able to figure it out in a split second :) I have a List Box and a Combo Box. Based on the selection the user...
3
by: mbedford | last post by:
In my asset and employee database I have Departments and Subdepartments. In the forms I want to filter the Subdepartment combo boxes based on the selection in the Department combo box. Combo...
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.