Hello all Experts,
I've inherited a .mdb with hundreds of thousands of records the problem is that there is no structure to the tables.
The issue I'm dealing with now is the following:
The table includes 5 columns, ID, Month1, Amount1, Month2, Amount2.
The problem is that each one of the Month an Amount fields have multiple records separated by the + sign.
Note: Not all the ID's have the same number of records in each column (in fact they very rarely do).
The question is how can I split each record to a separate field?
I've tried using this query
The Testsplit function is
But I get Run-Time error '9' - Subscript out of range
What am I doing wrong? How can I accomplish the above?
Attached please find a sample with some data.
Your assistance is most appreciated.
p.s. I wasn't sure if this is the proper forum for this question since it involves vba, or if the query forum is more appropriate, since I'm using a query, yet I decided to post it here because I'd rather use pure vba that way I have all code in one place as apposed to using a function with a query.
I've inherited a .mdb with hundreds of thousands of records the problem is that there is no structure to the tables.
The issue I'm dealing with now is the following:
The table includes 5 columns, ID, Month1, Amount1, Month2, Amount2.
The problem is that each one of the Month an Amount fields have multiple records separated by the + sign.
Note: Not all the ID's have the same number of records in each column (in fact they very rarely do).
The question is how can I split each record to a separate field?
I've tried using this query
Code:
SELECT MyTable.ID, MyTable.Amount1, IIf(IsNull(Testsplit([Amount1],0)),"",Testsplit([Amount1],0)) AS Part1, IIf(IsNull(Testsplit([Amount1],1)),"",Testsplit([Amount1],1)) AS Part2, IIf(IsNull(Testsplit([Amount1],2)),"",Testsplit([Amount1],2)) AS Part3, IIf(IsNull(Testsplit([Amount1],3)),"",Testsplit([Amount1],3)) AS Part4, IIf(IsNull(Testsplit([Amount1],4)),"",Testsplit([Amount1],4)) AS Part5, IIf(IsNull(Testsplit([Amount1],5)),"",Testsplit([Amount1],5)) AS Part6, IIf(IsNull(Testsplit([Amount1],6)),"",Testsplit([Amount1],6)) AS Part7, IIf(IsNull(Testsplit([Amount1],7)),"",Testsplit([Amount1],7)) AS Part8, IIf(IsNull(Testsplit([Amount1],8)),"",Testsplit([Amount1],8)) AS Part9, IIf(IsNull(Testsplit([Amount1],9)),"",Testsplit([Amount1],9)) AS Part10
FROM MyTable;
Code:
Function TestSplit(strInput As String, intNr As Integer)
TestSplit = Split(strInput, "+")(intNr)
End Function
What am I doing wrong? How can I accomplish the above?
Attached please find a sample with some data.
Your assistance is most appreciated.
p.s. I wasn't sure if this is the proper forum for this question since it involves vba, or if the query forum is more appropriate, since I'm using a query, yet I decided to post it here because I'd rather use pure vba that way I have all code in one place as apposed to using a function with a query.