tractorvix
Technical User
I've managed to normalise most of my tables, but there is on that is causing me problems!
It kind of contains 2 set of data and looks like:
01/01/08 01/02/08 etc
base 5 5.5
Product
A 100 150
B 10 20
I can successfully take the base numbers out and normalise them into a table, but I'm struggling with the product data as my code works on BOF and EOF. Is there a way that I can state the starting row, rather than using BOF?
Private Function NormaliseScenarioData(InputTable As String, OutputTable As String, FieldName As String, StartPoint As Integer)
Dim rs As DAO.Recordset
Dim x As Integer
Dim sql As String
On Error GoTo errorhandler
y = CurrentDb.TableDefs(InputTable).Fields.Count
Set rs = CurrentDb.OpenRecordset(InputTable)
If rs.EOF And rs.BOF Then
Exit Function
End If
DoCmd.SetWarnings False
DoCmd.RunSQL "DELETE " & OutputTable & ".*" & _
"FROM " & OutputTable & ";"
Do Until rs.EOF
RunCode:
For x = StartPoint + 2 To y - 1
sql = "INSERT INTO " & OutputTable & "(ProdXrefID, Scenario, dateval, " & FieldName & ")" & _
" VALUES(" & rs(StartPoint) & "," & rs(StartPoint + 1) & ",'" & rs(x).Name & _
"'," & rs(x) & ")"
DoCmd.RunSQL sql
Next x
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
DoCmd.SetWarnings True
Exit Function
errorhandler:
Resume RunCode
End Function
Thanks
Vicky
It kind of contains 2 set of data and looks like:
01/01/08 01/02/08 etc
base 5 5.5
Product
A 100 150
B 10 20
I can successfully take the base numbers out and normalise them into a table, but I'm struggling with the product data as my code works on BOF and EOF. Is there a way that I can state the starting row, rather than using BOF?
Private Function NormaliseScenarioData(InputTable As String, OutputTable As String, FieldName As String, StartPoint As Integer)
Dim rs As DAO.Recordset
Dim x As Integer
Dim sql As String
On Error GoTo errorhandler
y = CurrentDb.TableDefs(InputTable).Fields.Count
Set rs = CurrentDb.OpenRecordset(InputTable)
If rs.EOF And rs.BOF Then
Exit Function
End If
DoCmd.SetWarnings False
DoCmd.RunSQL "DELETE " & OutputTable & ".*" & _
"FROM " & OutputTable & ";"
Do Until rs.EOF
RunCode:
For x = StartPoint + 2 To y - 1
sql = "INSERT INTO " & OutputTable & "(ProdXrefID, Scenario, dateval, " & FieldName & ")" & _
" VALUES(" & rs(StartPoint) & "," & rs(StartPoint + 1) & ",'" & rs(x).Name & _
"'," & rs(x) & ")"
DoCmd.RunSQL sql
Next x
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
DoCmd.SetWarnings True
Exit Function
errorhandler:
Resume RunCode
End Function
Thanks
Vicky