W
Wouter
Hiya all,
I need some help to get my code running. I must say that I'm quit new with
VB / VBA so maybe my question is a bit stupid. But anyway I would be really
happy when the following code will run nice and smoothly.
The first question I have: Is the SQL after the DoCmd.sql the same code as
the sql access uses when you look in query designer view / sql? Because my
code comes straight from there.
The second question I have, could someone check the code and see what's
going on. The query stops when he is at:
DoCmd.RunSQL (mySQL) so apparantly the sql in red is incorrect.
( I know that the table collumns has spaces in the name and that that isn't
very good for the sql, access uses [] to work with it, and i cant change
these name because it isn't my database.
I expect that the sql behind mySQL1 also is incorrect like the first one and
so on.
Your help would be grateful!
Thanks in advance,
Wouter
Option Compare Database
Option Explicit
Sub UpdateCustomerCode()
Dim I As Integer
Dim mySQL As String
mySQL = "INSERT INTO [Customer IDA] ( Code, Range, [EBC Tier], NNI ) SELECT
[1381 data].Code, [1381 data].Range, [1381 data].[EBC Tier], [1381 data].NNI
FROM [1381 data] WHERE ((([1381 data].Code)=1381));"
DoCmd.SetWarnings False
For I = 1 To 8
Select Case I
Case 1
DoCmd.RunSQL (mySQL)
Dim mySQL1 As String
mySQL1 = "UPDATE [Customer IDA] SET [Customer IDA].Code = 138120 WHERE
((([Customer IDA].Code)=1381));"
DoCmd.RunSQL (mySQL1)
Case 2
DoCmd.RunSQL (mySQL)
Dim mySQL2 As String
mySQL2 = "UPDATE [Customer IDA] SET [Customer IDA].Code = 138124 WHERE
((([Customer IDA].Code)=1381));"
DoCmd.RunSQL (mySQL2)
Case 3
DoCmd.RunSQL (mySQL)
Dim mySQL3 As String
mySQL3 = "UPDATE [Customer IDA] SET [Customer IDA].Code = 138125 WHERE
((([Customer IDA].Code)=1381));"
DoCmd.RunSQL (mySQL3)
Case 4
DoCmd.RunSQL (mySQL)
Dim mySQL4 As String
mySQL4 = "UPDATE [Customer IDA] SET [Customer IDA].Code = 138126 WHERE
((([Customer IDA].Code)=1381));"
DoCmd.RunSQL (mySQL4)
Case 5
DoCmd.RunSQL (mySQL)
Dim mySQL5 As String
mySQL5 = "UPDATE [Customer IDA] SET [Customer IDA].Code = 138127 WHERE
((([Customer IDA].Code)=1381));"
DoCmd.RunSQL (mySQL5)
Case 6
DoCmd.RunSQL (mySQL)
Dim mySQL6 As String
mySQL6 = "UPDATE [Customer IDA] SET [Customer IDA].Code = 138128 WHERE
((([Customer IDA].Code)=1381));"
DoCmd.RunSQL (mySQL6)
Case 7
DoCmd.RunSQL (mySQL)
Dim mySQL7 As String
mySQL7 = "UPDATE [Customer IDA] SET [Customer IDA].Code = 138129 WHERE
((([Customer IDA].Code)=1381));"
DoCmd.RunSQL (mySQL7)
Case 8
DoCmd.RunSQL (mySQL)
Dim mySQL8 As String
mySQL8 = "UPDATE [Customer IDA] SET [Customer IDA].Code = 1382 WHERE
((([Customer IDA].Code)=1381));"
DoCmd.RunSQL (mySQL8)
End Select
Next
DoCmd.SetWarnings True
MsgBox ("Table is ready")
End Sub
I need some help to get my code running. I must say that I'm quit new with
VB / VBA so maybe my question is a bit stupid. But anyway I would be really
happy when the following code will run nice and smoothly.
The first question I have: Is the SQL after the DoCmd.sql the same code as
the sql access uses when you look in query designer view / sql? Because my
code comes straight from there.
The second question I have, could someone check the code and see what's
going on. The query stops when he is at:
DoCmd.RunSQL (mySQL) so apparantly the sql in red is incorrect.
( I know that the table collumns has spaces in the name and that that isn't
very good for the sql, access uses [] to work with it, and i cant change
these name because it isn't my database.
I expect that the sql behind mySQL1 also is incorrect like the first one and
so on.
Your help would be grateful!
Thanks in advance,
Wouter
Option Compare Database
Option Explicit
Sub UpdateCustomerCode()
Dim I As Integer
Dim mySQL As String
mySQL = "INSERT INTO [Customer IDA] ( Code, Range, [EBC Tier], NNI ) SELECT
[1381 data].Code, [1381 data].Range, [1381 data].[EBC Tier], [1381 data].NNI
FROM [1381 data] WHERE ((([1381 data].Code)=1381));"
DoCmd.SetWarnings False
For I = 1 To 8
Select Case I
Case 1
DoCmd.RunSQL (mySQL)
Dim mySQL1 As String
mySQL1 = "UPDATE [Customer IDA] SET [Customer IDA].Code = 138120 WHERE
((([Customer IDA].Code)=1381));"
DoCmd.RunSQL (mySQL1)
Case 2
DoCmd.RunSQL (mySQL)
Dim mySQL2 As String
mySQL2 = "UPDATE [Customer IDA] SET [Customer IDA].Code = 138124 WHERE
((([Customer IDA].Code)=1381));"
DoCmd.RunSQL (mySQL2)
Case 3
DoCmd.RunSQL (mySQL)
Dim mySQL3 As String
mySQL3 = "UPDATE [Customer IDA] SET [Customer IDA].Code = 138125 WHERE
((([Customer IDA].Code)=1381));"
DoCmd.RunSQL (mySQL3)
Case 4
DoCmd.RunSQL (mySQL)
Dim mySQL4 As String
mySQL4 = "UPDATE [Customer IDA] SET [Customer IDA].Code = 138126 WHERE
((([Customer IDA].Code)=1381));"
DoCmd.RunSQL (mySQL4)
Case 5
DoCmd.RunSQL (mySQL)
Dim mySQL5 As String
mySQL5 = "UPDATE [Customer IDA] SET [Customer IDA].Code = 138127 WHERE
((([Customer IDA].Code)=1381));"
DoCmd.RunSQL (mySQL5)
Case 6
DoCmd.RunSQL (mySQL)
Dim mySQL6 As String
mySQL6 = "UPDATE [Customer IDA] SET [Customer IDA].Code = 138128 WHERE
((([Customer IDA].Code)=1381));"
DoCmd.RunSQL (mySQL6)
Case 7
DoCmd.RunSQL (mySQL)
Dim mySQL7 As String
mySQL7 = "UPDATE [Customer IDA] SET [Customer IDA].Code = 138129 WHERE
((([Customer IDA].Code)=1381));"
DoCmd.RunSQL (mySQL7)
Case 8
DoCmd.RunSQL (mySQL)
Dim mySQL8 As String
mySQL8 = "UPDATE [Customer IDA] SET [Customer IDA].Code = 1382 WHERE
((([Customer IDA].Code)=1381));"
DoCmd.RunSQL (mySQL8)
End Select
Next
DoCmd.SetWarnings True
MsgBox ("Table is ready")
End Sub