I have attached an example of what I am wanting to do. Please let me know if you have any additional questions or need more information from me. Thanks.
I've produced your results exactly as requested, but unfortunately the code is rather cumbersome and complex, and I honestly do not have the time to refine it. It will also only work for a MAXIMUM of 3 Duplicates on the [UPN]. I will post what I have, and make the Test Database available to you as an Attachment, so that you may further develop it should you so desire. - Dim MyDB As DAO.Database
-
Dim rstUniqueUPNs As DAO.Recordset 'Contains the Unique UPNs
-
Dim rstOrig As DAO.Recordset 'Records in tblOriginal with Unique [UPN]s
-
Dim rstFinal As DAO.Recordset 'Will write the Final Results
-
Dim intNumOfUPNs As Integer
-
Dim intCounter As Integer
-
Dim varRes09 As Variant
-
Dim varRes08 As Variant
-
Dim varYrBlt As Variant
-
-
CurrentDb.Execute "DELETE * FROM tblConsolidated", dbFailOnError
-
-
Set MyDB = CurrentDb
-
Set rstUniqueUPNs = MyDB.OpenRecordset("SELECT DISTINCT [UPN] from tblOriginal", dbOpenForwardOnly)
-
Set rstFinal = MyDB.OpenRecordset("tblConsolidated", dbOpenDynaset)
-
-
With rstUniqueUPNs
-
Do While Not .EOF
-
intNumOfUPNs = DCount("*", "tblOriginal", "[UPN] = " & ![UPN])
-
Set rstOrig = MyDB.OpenRecordset("SELECT * FROM tblOriginal WHERE [UPN] = " & ![UPN], dbOpenSnapshot)
-
rstOrig.MoveLast: rstOrig.MoveFirst 'Need 'exact' Recordcount
-
Select Case rstOrig.RecordCount
-
Case 1
-
rstFinal.AddNew
-
rstFinal![UPN] = rstOrig![UPN]
-
rstFinal![Res09_1] = rstOrig![Res09]
-
rstFinal![Res08_1] = rstOrig![Res08]
-
rstFinal![YearBuilt_1] = rstOrig![YearBuilt]
-
rstFinal.Update
-
Case 2
-
For intCounter = 1 To intNumOfUPNs
-
varRes09 = varRes09 & rstOrig![Res09] & ";"
-
varRes08 = varRes08 & rstOrig![Res08] & ";"
-
varYrBlt = varYrBlt & rstOrig![YearBuilt] & ";"
-
rstOrig.MoveNext
-
Next
-
rstFinal.AddNew
-
rstFinal![UPN] = ![UPN]
-
rstFinal![Res09_1] = Split(varRes09, ";")(0)
-
rstFinal![Res09_2] = Split(varRes09, ";")(1)
-
rstFinal![Res08_1] = Split(varRes08, ";")(0)
-
rstFinal![Res08_2] = Split(varRes08, ";")(1)
-
rstFinal![YearBuilt_1] = Split(varYrBlt, ";")(0)
-
rstFinal![YearBuilt_2] = Split(varYrBlt, ";")(1)
-
rstFinal.Update
-
Case 3
-
For intCounter = 1 To intNumOfUPNs
-
varRes09 = varRes09 & rstOrig![Res09] & ";"
-
varRes08 = varRes08 & rstOrig![Res08] & ";"
-
varYrBlt = varYrBlt & rstOrig![YearBuilt] & ";"
-
rstOrig.MoveNext
-
Next
-
rstFinal.AddNew
-
rstFinal![UPN] = ![UPN]
-
rstFinal![Res09_1] = Split(varRes09, ";")(0)
-
rstFinal![Res09_2] = Split(varRes09, ";")(1)
-
rstFinal![Res09_3] = Split(varRes09, ";")(2)
-
rstFinal![Res08_1] = Split(varRes08, ";")(0)
-
rstFinal![Res08_2] = Split(varRes08, ";")(1)
-
rstFinal![Res08_3] = Split(varRes08, ";")(2)
-
rstFinal![YearBuilt_1] = Split(varYrBlt, ";")(0)
-
rstFinal![YearBuilt_2] = Split(varYrBlt, ";")(1)
-
rstFinal![YearBuilt_3] = Split(varYrBlt, ";")(2)
-
rstFinal.Update
-
Case Else
-
End Select
-
varRes09 = Null
-
varRes08 = Null
-
varYrBlt = Null
-
.MoveNext
-
Loop
-
End With
-
-
rstFinal.Close
-
rstOrig.Close
-
rstUniqueUPNs.Close
-
Set rstFinal = Nothing
-
Set rstOrig = Nothing
-
Set rstUniqueUPNs = Nothing
-
-
DoCmd.OpenTable "tblConsolidated", acViewNormal, acReadOnly
-
DoCmd.Maximize
P.S. - Any questions, feel free to ask.
6 2358 @stateemk
What is the Maximum Number of Duplicates that can exist in the Original Table for a given UPN?
@stateemk
That significantly complicates matters but I'll see what I can do.
I've produced your results exactly as requested, but unfortunately the code is rather cumbersome and complex, and I honestly do not have the time to refine it. It will also only work for a MAXIMUM of 3 Duplicates on the [UPN]. I will post what I have, and make the Test Database available to you as an Attachment, so that you may further develop it should you so desire. - Dim MyDB As DAO.Database
-
Dim rstUniqueUPNs As DAO.Recordset 'Contains the Unique UPNs
-
Dim rstOrig As DAO.Recordset 'Records in tblOriginal with Unique [UPN]s
-
Dim rstFinal As DAO.Recordset 'Will write the Final Results
-
Dim intNumOfUPNs As Integer
-
Dim intCounter As Integer
-
Dim varRes09 As Variant
-
Dim varRes08 As Variant
-
Dim varYrBlt As Variant
-
-
CurrentDb.Execute "DELETE * FROM tblConsolidated", dbFailOnError
-
-
Set MyDB = CurrentDb
-
Set rstUniqueUPNs = MyDB.OpenRecordset("SELECT DISTINCT [UPN] from tblOriginal", dbOpenForwardOnly)
-
Set rstFinal = MyDB.OpenRecordset("tblConsolidated", dbOpenDynaset)
-
-
With rstUniqueUPNs
-
Do While Not .EOF
-
intNumOfUPNs = DCount("*", "tblOriginal", "[UPN] = " & ![UPN])
-
Set rstOrig = MyDB.OpenRecordset("SELECT * FROM tblOriginal WHERE [UPN] = " & ![UPN], dbOpenSnapshot)
-
rstOrig.MoveLast: rstOrig.MoveFirst 'Need 'exact' Recordcount
-
Select Case rstOrig.RecordCount
-
Case 1
-
rstFinal.AddNew
-
rstFinal![UPN] = rstOrig![UPN]
-
rstFinal![Res09_1] = rstOrig![Res09]
-
rstFinal![Res08_1] = rstOrig![Res08]
-
rstFinal![YearBuilt_1] = rstOrig![YearBuilt]
-
rstFinal.Update
-
Case 2
-
For intCounter = 1 To intNumOfUPNs
-
varRes09 = varRes09 & rstOrig![Res09] & ";"
-
varRes08 = varRes08 & rstOrig![Res08] & ";"
-
varYrBlt = varYrBlt & rstOrig![YearBuilt] & ";"
-
rstOrig.MoveNext
-
Next
-
rstFinal.AddNew
-
rstFinal![UPN] = ![UPN]
-
rstFinal![Res09_1] = Split(varRes09, ";")(0)
-
rstFinal![Res09_2] = Split(varRes09, ";")(1)
-
rstFinal![Res08_1] = Split(varRes08, ";")(0)
-
rstFinal![Res08_2] = Split(varRes08, ";")(1)
-
rstFinal![YearBuilt_1] = Split(varYrBlt, ";")(0)
-
rstFinal![YearBuilt_2] = Split(varYrBlt, ";")(1)
-
rstFinal.Update
-
Case 3
-
For intCounter = 1 To intNumOfUPNs
-
varRes09 = varRes09 & rstOrig![Res09] & ";"
-
varRes08 = varRes08 & rstOrig![Res08] & ";"
-
varYrBlt = varYrBlt & rstOrig![YearBuilt] & ";"
-
rstOrig.MoveNext
-
Next
-
rstFinal.AddNew
-
rstFinal![UPN] = ![UPN]
-
rstFinal![Res09_1] = Split(varRes09, ";")(0)
-
rstFinal![Res09_2] = Split(varRes09, ";")(1)
-
rstFinal![Res09_3] = Split(varRes09, ";")(2)
-
rstFinal![Res08_1] = Split(varRes08, ";")(0)
-
rstFinal![Res08_2] = Split(varRes08, ";")(1)
-
rstFinal![Res08_3] = Split(varRes08, ";")(2)
-
rstFinal![YearBuilt_1] = Split(varYrBlt, ";")(0)
-
rstFinal![YearBuilt_2] = Split(varYrBlt, ";")(1)
-
rstFinal![YearBuilt_3] = Split(varYrBlt, ";")(2)
-
rstFinal.Update
-
Case Else
-
End Select
-
varRes09 = Null
-
varRes08 = Null
-
varYrBlt = Null
-
.MoveNext
-
Loop
-
End With
-
-
rstFinal.Close
-
rstOrig.Close
-
rstUniqueUPNs.Close
-
Set rstFinal = Nothing
-
Set rstOrig = Nothing
-
Set rstUniqueUPNs = Nothing
-
-
DoCmd.OpenTable "tblConsolidated", acViewNormal, acReadOnly
-
DoCmd.Maximize
P.S. - Any questions, feel free to ask.
Thanks so much for all your help.
What's the necessity of making the UPN field a primary key? The original table has a much easier structure to work with than your intended result table.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: merdaad |
last post by:
I am trying to read multiple rows from an SP into a datalist.
I can easily read and display multiple rows if I use a select statement but when I call an SP to send me a few rows, I only get back...
|
by: SSP |
last post by:
Dear ASP.NETers,
How would I insert multiple rows of data from a web form?
Are there any tute's and stuff around. Couldn't find any myself.
Thanks in advance.
SSP
|
by: Arsen V. |
last post by:
Hello,
What is the optimal way to insert multiple rows (around 1000) from a web
application into a table?
The user enters multiple lines into a text box (up to 10,000). The ASP.NET...
|
by: manjub |
last post by:
Hi,
I am trying to add ability to delete multiple rows from a DataGridView
in my application. When user selects multiple rows and presses delete
button, I want to show a message asking to user...
|
by: patrick.waldo |
last post by:
Hi all,
I was just curious if there was a built-in or a more efficient way to
do take multiple rows of information and write them into excel using
pyExcelerator. This is how I resolved the...
|
by: =?Utf-8?B?S2F5xLFoYW4=?= |
last post by:
In my project,i added datagridview to my form , i transfered my table to
datagridview and added multiple rows and when i called dataadapther.update
,,result is ok. But when i tried it for the...
|
by: Michael |
last post by:
It seems that a gridview allows us to delete only a single row at a time.
How to extend this functionality to select multiple rows and delete all of
the selected rows in a single stroke? just like...
|
by: nigelesquire |
last post by:
Please help!
I'm trying to clone and delete multiple rows with JavaScript.
I need two delete buttons that work...!
I only have one for now, but it's not working properly, the output count is...
|
by: Vinda |
last post by:
Hi Bytes,
Using a previous question as a base Access 2000 Inserting multiple rows based on a date range.
I also wanted to insert multiple rows into a table according to a date range supplied by a...
|
by: emceemic |
last post by:
Is there a way to show multiple rows per row if required?
For example, say the table I currently have show the following data:
Impact to Business, Business Owner Name, ...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: 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...
| |