<mctime@hot-shot.comwrote
Quote:
Some Pseudo code would be great for me to
start with as this is all i'm after due to the fact
that I have multiple raw data sets that are
all different and I just need a starting point.
Here's some real code, instead. I put it in the Click event of a command
button.
The raw input was in tblPartsRaw, and the normalized output was placed in
tblPartsNor. Each table had text fields named MfrName, Product, PartCode,
and OtherInfo. The PartCode Field of tblPartsRaw contained the multi-value,
comma-separated, values you described, which were "unpacked" into separate
Records in tblPartsNor, whose PartCode Field only contained one part code.
Larry Linson
Microsoft Access MVP
Private Sub cmdRunSplitCode_Click()
'---------------------------------------------------------------------------------------
' Procedure : cmdRunSplitCode_Click
' DateTime : 3/25/2007 15:10
' Author : LARRY LINSON
' Purpose : Runs "split-code" to generate multiple records
' from single record with multi-value field
'
'---------------------------------------------------------------------------------------
On Error GoTo PROC_Error
Dim db As DAO.Database
Dim rsRAW As DAO.Recordset
Dim rsNOR As DAO.Recordset
Dim aPCodes() As String
Dim i As Integer
Set db = CurrentDb
Set rsRAW = db.OpenRecordset("tblPartsRaw")
Set rsNOR = db.OpenRecordset("tblPartsNor")
If (Not rsRAW.BOF And Not rsRAW.EOF) Then
rsRAW.MoveFirst
Do Until rsRAW.EOF
aPCodes = Split(rsRAW!PartCode, ",", -1)
For i = LBound(aPCodes()) To UBound(aPCodes())
rsNOR.AddNew
rsNOR("MfrName") = rsRAW("MfrName")
rsNOR("Product") = rsRAW("Product")
rsNOR("PartCode") = aPCodes(i)
rsNOR("OtherInfo") = rsRAW("OtherInfo")
rsNOR.Update
Next i
rsRAW.MoveNext
Loop
Else
MsgBox "No Records in Input"
End If
rsRAW.Close
Set rsRAW = Nothing
rsNOR.Close
Set rsNOR = Nothing
Set db = Nothing
PROC_Exit:
Exit Sub
PROC_Error:
On Error GoTo 0
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure
cmdRunSplitCode_Click of VBA Document Form_Form2"
Resume PROC_Exit:
End Sub
Private Sub cmdRunSplitCode_Click()
'---------------------------------------------------------------------------------------
' Procedure : cmdRunSplitCode_Click
' DateTime : 3/25/2007 15:10
' Author : LARRY LINSON
' Purpose : Runs "split-code" to generate multiple records
' from single record with multi-value field
'
'---------------------------------------------------------------------------------------
On Error GoTo PROC_Error
Dim db As DAO.Database
Dim rsRAW As DAO.Recordset
Dim rsNOR As DAO.Recordset
Dim aPCodes() As String
Dim i As Integer
Set db = CurrentDb
Set rsRAW = db.OpenRecordset("tblPartsRaw")
Set rsNOR = db.OpenRecordset("tblPartsNor")
If (Not rsRAW.BOF And Not rsRAW.EOF) Then
rsRAW.MoveFirst
Do Until rsRAW.EOF
aPCodes = Split(rsRAW!PartCode, ",", -1)
For i = LBound(aPCodes()) To UBound(aPCodes())
rsNOR.AddNew
rsNOR("MfrName") = rsRAW("MfrName")
rsNOR("Product") = rsRAW("Product")
rsNOR("PartCode") = aPCodes(i)
rsNOR("OtherInfo") = rsRAW("OtherInfo")
rsNOR.Update
Next i
rsRAW.MoveNext
Loop
Else
MsgBox "No Records in Input"
End If
rsRAW.Close
Set rsRAW = Nothing
rsNOR.Close
Set rsNOR = Nothing
Set db = Nothing
PROC_Exit:
Exit Sub
PROC_Error:
On Error GoTo 0
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure
cmdRunSplitCode_Click of VBA Document Form_Form2"
Resume PROC_Exit:
End Sub