Marshall Brooks
Member
- Local time
- Today, 09:52
- Joined
- Feb 28, 2023
- Messages
- 696
Alternatively, is there a way to create a different query which would have the names from the employee table and these values (and update when the table is updated?)
You can union many tables and queries as long as the number of columns and datatypes match.can I union the new table in front of the existing query?
SELECT tblEmployees.FullName, Trim(Mid([tblEmployees].[FullName],InStr([tblEmployees].[FullName]," ")+1)) AS LastName
FROM tblEmployees
UNION
SELECT "Unassigned", "1"
FROM
tblEmployees
Union
SELECT
"SPO", "2"
From
tblEmployees
Order by 2,1
FullName | LastName |
---|---|
Unassigned | 1 |
SPO | 2 |
Steve Anderson | Anderson |
Tom Baker | Baker |
Marshall Brooks | Brooks |
Joe Smith | Smith |
Private Sub UserForm_Activate()
Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("Select FullName from qrySortedNames order by lastName")
Me.cmboNames.Value = "--- Select Employee ---"
Do While Not rs.EOF
Me.cmboNames.AddItem rs!FullName
rs.MoveNext
Loop
End Sub
Private Sub UserForm_Activate()
Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("select lastname & ', ' & firstname as FullName from tblStudent order by LastName, firstname")
Me.cmboName.AddItem "Unassigned"
Me.CmboName.AddItem "SPO"
Do While Not rs.EOF
Me.cmboNames.AddItem rs!FullName
rs.MoveNext
Loop
End Sub
Now I am getting confused. We are back to using an Access data form not a User Form?First off, "Modify your code to use the new query" - is written if this were for the userform. This is for a combobox on an Access dataform.
FullName |
---|
Unassigned |
SPO |
Steve Anderson |
Tom Baker |
Marshall Brooks |
Joe Smith |
Kind of confused again. Did you not look at the query and the results?If your query somehow creates it's own second column in the query itself, that is pretty cool
SELECT tblEmployees.Names FROM tblEmployees ORDER BY
Trim$(Mid$(tblEmployees.Names, InStr(tblEmployees.Names, " ") + 1))
SELECT tblEmployees.Names FROM tblEmployees UNION SELECT tblEmployeesOther.Names FROM tblEmployeesOther ORDER BY
Trim$(Mid$(tblEmployees.Names, InStr(tblEmployees.Names, " ") + 1))
SELECT tblEmployees.Names FROM tblEmployees UNION SELECT tblEmployeesOther.Names FROM tblEmployeesOther ORDER BY
Trim$(Mid$(Names, InStr(Names, " ") + 1))
If you want to store Unassigned and SPO in a separate table then to make this easier in that tableI'd prefer to use separate tables
Are you following anything I am saying? Sorry, but I do not know how to be any more clear. Need to read what I am writing. What I am saying and what you are doing seems to be 180 out.Works but doesn't give me the "Unassigned" and "SPO" values
Correct - I said that in Reply #20, but I think you missed it. I have an Access data form with three comboboxes. Two of the boxes just use the employees names. That was working properly, so I didn't post it here. The UserForm combobox didn't work with the query, so you got that working for me. One of the data form combo boxes needs "Unassigned" and "SPO" added at the top and that is what I am working on now.Now I am getting confused. We are back to using an Access data form not a User Form?
I looked at the query and results. I haven't tested them, and I don't follow exactly how it is working. i.e. The query creates a second calculated column IN THE QUERY would work great and would be simple. The query creates a second calculated column IN THE TABLE will probably create issues when I re-open the FE, but perhaps not.Kind of confused again. Did you not look at the query and the results?
The query clearly creates a second calculated column called "LastName" taken from the FullName column. The unions stick either a 1 or 2 in this column to get the correct order.
Yes, I'm following - so far, I've tested Reply #22 and couldn't get it to work, leading to Reply #33.Are you following anything I am saying? Sorry, but I do not know how to be any more clear. Need to read what I am writing. What I am saying and what you are doing seems to be 180 out.
No it creates it in the query not in a table. This is a fundamental of sql queries. You can create a column by concatenating other fields, using a literal, performing functions (min, max, sum, avg etc, iif), etc.The query creates a second calculated column IN THE TABLE will probably create issues when I re-open the FE
SELECT tblEmployees.FullName, Trim(Mid([tblEmployees].[FullName],InStr([tblEmployees].[FullName]," ")+1)) AS LastName
FROM tblEmployees
In my example I called this tblChoices because EmployeesOther sounded like a poor name unless there are other values in there.I'm going to make a new table called tblEmployeesOther with a field Names and values of "Unassigned" and "SPO"
SELECT "Unassigned", "1" FROM tblEmployees
There are no records Added anywhere. In the query it creates columns and rows, but these do not reside in any table. Records are stored in tables.Adding records can be done without errors - well - if I do that, my other comboboxes and my userform will have Unassigned and SPO added as well, which I don't want to have happen.
I do not know how to prove it any better. I post real results from the query and clearly it does as described.So to use this method, does it just work somehow, or do I need to add records to tblEmployees with SPO and Unassigned in the Names field