Heythere82
Registered User.
- Local time
- Today, 11:57
- Joined
- Feb 17, 2016
- Messages
- 14
Hi
I'm trying to figure out how to copy values from one table to another using VB and SQL. On TableA, I have a list of names. On TableB, I have office room assignments. I want to assign names from TableA to office rooms in TableB (See Below)
TableA
ID Name
1...Bobby
2...Tina
3...Fred
... ...
TableB
3...114
4...116
... ...
The three issues making it difficult to solve are:
1) I only want to assign names to records where the Name field is empty in TableB.
2) I dont want already assigned Names to be duplicated/ assigned to another office.
3) I must have Office Rooms assigned in the same order as the list of names in TableA. i.e. Bobby gets the 1st available office on the office list.
I have written a SQL string that Im feeding into a DoCmd. It does autofill names to TableB, but I am lost as how to prevent assigned names from being repeated though. :banghead:
Dim strSQL As String
strSQL = "UPDATE TableB, TableA SET TableB.Name = TableA.Name
WHERE TableB.ID = TableA.ID AND TableB.Name IS NULL"
Debug.Print strSQL
DoCmd.RunSQL strSQL
I know one problem is I have the WHERE condition isolating rows where the ID matches, but Im not sure how else I could maintain the name order from TableA.
I looked up information about the SQL JOIN clauses and they sound promising. Every attempt at adding them to my string failed though.
Any suggestions?
I'm trying to figure out how to copy values from one table to another using VB and SQL. On TableA, I have a list of names. On TableB, I have office room assignments. I want to assign names from TableA to office rooms in TableB (See Below)
TableA
ID Name
1...Bobby
2...Tina
3...Fred
... ...
TableB
ID OfficeRoom Name
1...102A
2...102B..........Tina1...102A
3...114
4...116
... ...
The three issues making it difficult to solve are:
1) I only want to assign names to records where the Name field is empty in TableB.
2) I dont want already assigned Names to be duplicated/ assigned to another office.
3) I must have Office Rooms assigned in the same order as the list of names in TableA. i.e. Bobby gets the 1st available office on the office list.
I have written a SQL string that Im feeding into a DoCmd. It does autofill names to TableB, but I am lost as how to prevent assigned names from being repeated though. :banghead:
Dim strSQL As String
strSQL = "UPDATE TableB, TableA SET TableB.Name = TableA.Name
WHERE TableB.ID = TableA.ID AND TableB.Name IS NULL"
Debug.Print strSQL
DoCmd.RunSQL strSQL
I know one problem is I have the WHERE condition isolating rows where the ID matches, but Im not sure how else I could maintain the name order from TableA.
I looked up information about the SQL JOIN clauses and they sound promising. Every attempt at adding them to my string failed though.
Any suggestions?