MajP
You've got your good things, and you've got mine.
- Local time
- Today, 18:31
- Joined
- May 21, 2018
- Messages
- 9,501
I still do not really understand what you start with and how you get to the CSV. But I will assume somehow you get a weird CSV in this format with Models in the first row and parts below it.
If you can preprocess outside the database into the correct format it would easier. It should look like this.
I did it in code. This normalize the CSV.
Now you can do any query you want.
I can group by part and count how many model that part is in.
I can query to see which models have two specific parts. These models have both parts in the query.
If you can preprocess outside the database into the correct format it would easier. It should look like this.
I did it in code. This normalize the CSV.
Code:
Public Sub FillModelParts()
Const ImportTable = "models_Parts_Example"
Const tableName = "tblModelParts"
Const PartField = "PartNumber"
Const ModelField = "ModelNumber"
Dim rs As DAO.Recordset
Dim fld As DAO.Field
Dim PartNumber As String
Dim modelNumber As String
Dim strSql As String
Set rs = CurrentDb.OpenRecordset(ImportTable, dbOpenDynaset)
For Each fld In rs.Fields
Do While Not rs.EOF
Debug.Print rs.AbsolutePosition
If rs.AbsolutePosition = 0 Then
modelNumber = fld.Value
Else
If Not IsNull(fld.Value) Then
PartNumber = fld.Value
strSql = "insert into " & tableName & " (" & ModelField & ", " & PartField & ") values ('" & modelNumber & "', '" & PartNumber & "')"
Debug.Print strSql
CurrentDb.Execute strSql
End If
End If
rs.MoveNext
Loop
rs.MoveFirst
Next fld
End Sub
Now you can do any query you want.
I can group by part and count how many model that part is in.
I can query to see which models have two specific parts. These models have both parts in the query.