L
LJG
I have had this code passed to be to split data out of a table but am
finding the 'ref ' is not bringing the leading 0's into the table
i.e. original table:
000001 blu blk
what I want is:
000001 blu
000001 blk
What I get from this code is
1 blu
1 blk
code example below:
Sub PopulateNewTable()
Dim dbCurr As DAO.Database
Dim rst2t_new1 As DAO.Recordset
Dim lngLoop As Long
Dim lngRef As Long
Dim strColours As String
Dim strSQL As String
Dim varColours As Variant
strSQL = "SELECT ref, colours FROM t2t_new1"
Set dbCurr = CurrentDb()
Set rsOldData = dbCurr.OpenRecordset(strSQL)
Do While rsOldData.EOF = False
lngRef = rsOldData!ref
strColours = rsOldData!Colours
varColours = Split(strColours, " ")
If IsNull(varColours) = False Then
For lngLoop = LBound(varColours) To UBound(varColours)
strSQL = "INSERT INTO t2t_new2 (ref, colours) " & _
"VALUES (" & lngRef & ", '" & varColours(lngLoop) & "')"
dbCurr.Execute strSQL, dbFailOnError
Next lngLoop
End If
rsOldData.MoveNext
Loop
rsOldData.Close
Set rsOldData = Nothing
Set dbCurr = Nothing
End Sub
finding the 'ref ' is not bringing the leading 0's into the table
i.e. original table:
000001 blu blk
what I want is:
000001 blu
000001 blk
What I get from this code is
1 blu
1 blk
code example below:
Sub PopulateNewTable()
Dim dbCurr As DAO.Database
Dim rst2t_new1 As DAO.Recordset
Dim lngLoop As Long
Dim lngRef As Long
Dim strColours As String
Dim strSQL As String
Dim varColours As Variant
strSQL = "SELECT ref, colours FROM t2t_new1"
Set dbCurr = CurrentDb()
Set rsOldData = dbCurr.OpenRecordset(strSQL)
Do While rsOldData.EOF = False
lngRef = rsOldData!ref
strColours = rsOldData!Colours
varColours = Split(strColours, " ")
If IsNull(varColours) = False Then
For lngLoop = LBound(varColours) To UBound(varColours)
strSQL = "INSERT INTO t2t_new2 (ref, colours) " & _
"VALUES (" & lngRef & ", '" & varColours(lngLoop) & "')"
dbCurr.Execute strSQL, dbFailOnError
Next lngLoop
End If
rsOldData.MoveNext
Loop
rsOldData.Close
Set rsOldData = Nothing
Set dbCurr = Nothing
End Sub