G
Guest
I cannot figure out why this won't work. It doesn't like the variables in
the sql is the problem, but i can't figure out a way around it. I am goign
to have to have a TON of update queries if i can't get this to work.
the gist is trying to get the code to automatically run the update query
looking at 7 columns in a record, then move up one, and check the next 7 for
teh "code" which is #M# if it finds that code, copy that data, and the next
6 fields to anohter table.
Any advice???
Function MCodeUpdate()
Dim CODE As String
CODE = "#M#"
Dim CodeNum As Integer
Dim CodeNum1 As String
Dim CodeNum2 As String
Dim CodeNum3 As String
Dim CodeNum4 As String
Dim CodeNum5 As String
Dim CodeNum6 As String
Dim CodeNum7 As String
Dim SQL As String
For CodeNum = 38 To 100
CodeNum1 = "ImportTable.Field" & (CodeNum)
CodeNum2 = "ImportTable.Field" & (CodeNum + 1)
CodeNum3 = "ImportTable.Field" & (CodeNum + 2)
CodeNum4 = "ImportTable.Field" & (CodeNum + 3)
CodeNum5 = "ImportTable.Field" & (CodeNum + 4)
CodeNum6 = "ImportTable.Field" & (CodeNum + 5)
CodeNum7 = "ImportTable.Field" & (CodeNum + 6)
SQL = "INSERT INTO [M-Detail Table] ( ID, AccountNumber,
[M-Detail1], [M-Detail2], [M-Detail3], [M-Detail4], [M-Detail5], [M-Detail6],
[M-Detail7] )" & _
"SELECT ImportTable.ID, ImportTable.AccountNumber, CodeNum1,
CodeNum2, CodeNum3, CodeNum4, CodeNum5, CodeNum6, CodeNum7 " & _
"FROM [ImportTable] " & _
"WHERE CodeNum1 = CODE;"
DoCmd.RunSQL SQL
Next CodeNum
End Function
the sql is the problem, but i can't figure out a way around it. I am goign
to have to have a TON of update queries if i can't get this to work.
the gist is trying to get the code to automatically run the update query
looking at 7 columns in a record, then move up one, and check the next 7 for
teh "code" which is #M# if it finds that code, copy that data, and the next
6 fields to anohter table.
Any advice???
Function MCodeUpdate()
Dim CODE As String
CODE = "#M#"
Dim CodeNum As Integer
Dim CodeNum1 As String
Dim CodeNum2 As String
Dim CodeNum3 As String
Dim CodeNum4 As String
Dim CodeNum5 As String
Dim CodeNum6 As String
Dim CodeNum7 As String
Dim SQL As String
For CodeNum = 38 To 100
CodeNum1 = "ImportTable.Field" & (CodeNum)
CodeNum2 = "ImportTable.Field" & (CodeNum + 1)
CodeNum3 = "ImportTable.Field" & (CodeNum + 2)
CodeNum4 = "ImportTable.Field" & (CodeNum + 3)
CodeNum5 = "ImportTable.Field" & (CodeNum + 4)
CodeNum6 = "ImportTable.Field" & (CodeNum + 5)
CodeNum7 = "ImportTable.Field" & (CodeNum + 6)
SQL = "INSERT INTO [M-Detail Table] ( ID, AccountNumber,
[M-Detail1], [M-Detail2], [M-Detail3], [M-Detail4], [M-Detail5], [M-Detail6],
[M-Detail7] )" & _
"SELECT ImportTable.ID, ImportTable.AccountNumber, CodeNum1,
CodeNum2, CodeNum3, CodeNum4, CodeNum5, CodeNum6, CodeNum7 " & _
"FROM [ImportTable] " & _
"WHERE CodeNum1 = CODE;"
DoCmd.RunSQL SQL
Next CodeNum
End Function