Hi There,
I have a table of employees and the certificates they have. The fields in the table are all the possible certificates one can have and the records are set up as yes/no fields for if they have the certificate or not. I am trying to create a query that selects multiple fields (certificates) from the table using a list box with all the possible certificates and show me which employees have the selected certificates.
I have setup a form with the populated listbox from the certificate fields I have, but I cannot seem to link it to the query I am trying to run. I want the query to only show the employees that have the certificates that the user selects from the listbox.
Please Help!
7 5481
You will need to create the query programmatically. Create a query based on anything you like called qryDummy. Make sure that the Microsoft DAO library is checked in the references list. Then something like ... -
Dim db As DAO.Database
-
Dim qdf As DAO.QueryDef
-
Dim valSel As Variant
-
Dim strSQL As String
-
-
strSQL = "SELECT EmpID, EmpName FROM TableName WHERE "
-
For Each valSel In Me!ListboxName.ItemsSelected
-
strSQL = strSQL & "[" & Me!ListboxName.ItemData(valSel) & "]=True OR "
-
Next valSel
-
-
strSQL = Left(strSQL, Len(strSQL)-3 ' remove last OR from statement
-
-
Set db = CurrentDB
-
Set qdf = db.QueryDefs("qryDummy")
-
qdf.SQL = strSQL
-
-
qdf.Close
-
Set db = Nothing
-
-
End Sub
-
Mary
Thanks Mary!
Now that the list box is working properly, do you know how to get the selected listbox fields to show in the results as well in the line:
strSQL = "SELECT Name, selected listbox items FROM tblEmployeeCertification WHERE "
Regards,
Jeff
Try this ... -
Dim db As DAO.Database
-
Dim qdf As DAO.QueryDef
-
Dim valSel As Variant
-
Dim strSQL As String
-
Dim strCriteria As String
-
-
strSQL = "SELECT Name, "
-
-
For Each valSel In Me!ListboxName.ItemsSelected
-
strSQL = strSQL & Me!ListboxName.ItemData(valSel) & ", "
-
strCriteria = strCriteria & "[" & Me!ListboxName.ItemData(valSel) & "]=True OR "
-
Next valSel
-
-
strSQL = Left(strSQL, Len(strSQL)-2 ' remove last , from statement
-
strCriteria = Left(strCriteria, Len(strCriteria)-3 ' remove last OR from statement
-
strSQL = strSQL & " FROM tblEmployeeCertification WHERE " & strCriteria
-
-
Set db = CurrentDB
-
Set qdf = db.QueryDefs("qryDummy")
-
qdf.SQL = strSQL
-
-
qdf.Close
-
Set db = Nothing
-
-
End Sub
-
Mary
I seem to be getting a run-time error '3075' missing opererator in query expression. I can't seem to find it.
I seem to be getting a run-time error '3075' missing opererator in query expression. I can't seem to find it.
I have spaces in some of my field names which seems to be messing it up.
OK, this should work ... -
Dim db As DAO.Database
-
Dim qdf As DAO.QueryDef
-
Dim valSel As Variant
-
Dim strSQL As String
-
Dim strCriteria As String
-
-
strSQL = "SELECT Name, "
-
-
For Each valSel In Me!ListboxName.ItemsSelected
-
strSQL = strSQL & "[" & Me!ListboxName.ItemData(valSel) & "], "
-
strCriteria = strCriteria & "[" & Me!ListboxName.ItemData(valSel) & "]=True OR "
-
Next valSel
-
-
strSQL = Left(strSQL, Len(strSQL)-2 ' remove last , from statement
-
strCriteria = Left(strCriteria, Len(strCriteria)-3 ' remove last OR from statement
-
strSQL = strSQL & " FROM tblEmployeeCertification WHERE " & strCriteria
-
-
Set db = CurrentDB
-
Set qdf = db.QueryDefs("qryDummy")
-
qdf.SQL = strSQL
-
-
qdf.Close
-
Set db = Nothing
-
-
End Sub
-
Mary
Hey everyone,
This problem is similar to what I am trying to make. I have the same problem, but instead of using one table with yes/no records, I used a "many-to-many" relationship, with one table for the employees, one table for the certificates and a third table with records containing the employee ID and certificate ID (plus some extra information on when this certificate was obtained).
In this way, it is easier to update the list of certificates.
Is there a way to achieve the same thing? make a listbox containing the list of certificates and have a query display all the Employee names which are connected to at least all the certificates selected?
I don't know if it is similar in way of working, but it's worth the try.
Thanks in advance!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Skully Matjas |
last post by:
I am using the following code (created by the wizard) to
allow to bring my form to a particular entery. But when I
edit the entery (ex: put new information into a blank
cell), it puts that record...
|
by: Tim Pollard |
last post by:
Hi
I'm hoping someone can help me with an access problem I just can't get
my head around. I normally use access as a back end for asp pages,
just to hold data in tables, so queries within access...
|
by: Ian Davies |
last post by:
Hello
Needing help with a suitable solution.
I have extracted records into a table under three columns 'category',
'comment' and share (the category column also holds the index no of the
record...
|
by: xcelmind |
last post by:
Hello Dev. Guru,
I want to at this time introduce myself. I am Stanley Ojadovwa by name.
I’m a freelance and a newbie in web application development. I’m
currently using ASP as my application...
|
by: KevinADC |
last post by:
Note: You may skip to the end of the article if all you want is the perl code.
Introduction
Uploading files from a local computer to a remote web server has many useful purposes, the most...
|
by: bimeldip |
last post by:
Hi,
I have managed to create codes to display data from the database in a html page.I have gone on to create a page to allow users to manipulate the table via a html page. For instance users will be...
|
by: bimeldip |
last post by:
Hi,
I have managed to create codes to display data from the database in a html page.I have gone on to create a page to allow users to manipulate the table via a html page. For instance users will be...
|
by: Atli |
last post by:
You may be wondering why you would want to put your files “into” the database, rather than just onto the file-system. Well, most of the time, you wouldn’t.
In situations where your PHP application...
|
by: MMcCarthy |
last post by:
Rather than using the Access design view change the view to SQL. I am going to attempt to outline the general syntax used for SQL queries in Access.
Angle brackets <> are used in place of some...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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
|
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...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
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,...
|
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...
|
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...
| |