A
Anthony Lewis via AccessMonster.com
I have been fighting with this update for too long now. Here's the code I'm
trying to use:
Dim rs As DAO.Recordset
Dim strSql As String
strSql = "Select [Recommendations].Vehicle_ID, IIF
(category=121,RecommendText,'none') AS Box1, IIF
(category=146,RecommendText,'') AS 146, IIF(category=109,RecommendText,'')
AS 109, IIF(category = 148,RecommendText,'') AS 148, IIF
(category=149,RecommendText,'') AS 149, IIF(category=130,RecommendText,'')
AS 130, IIF(category=129,RecommendText,'') AS 129, IIF
(category=115,RecommendText,'') AS 115, IIF(category=120,RecommendText,'')
AS Box9, IIF(category=124,RecommendText,'') AS 124 FROM [Recommendations]
INNER JOIN [Category] ON [Recommendations].category=[Category].Code;"
' strSql = "Select Vehicle_ID from [Recommendations];"
Set rs = CurrentDb.OpenRecordset(strSql)
' process untill end of file
Do While rs.EOF = False
' Value Set for Testing Purposes here
If rs!Vehicle_ID = 1874 Then
' Showing Values Only For Testing
MsgBox _
rs!Vehicle_ID
Dim Veh_ID As String
Dim Maint As Variant
Maint = rs!Box1
Veh_ID = rs!Vehicle_ID
MsgBox _
[Veh_ID]
MsgBox _
[Maint]
Dim Sql As String
Sql = "Update [Recommendations_Master] set Recommendations_Vehicle_ID = "
& Veh_ID & _
", 120 = " & Veh_ID & _
", 121 = " & 121 & ";"
DoCmd.RunSQL (Sql)
rs.MoveNext
Else
rs.MoveNext
End If
Loop
rs.Close
The problem is in the update Sql. Two problems. The code is correct in
putting in the value for Veh_ID, but not for Maint or 121. 121 is a direct
field from the recordset. Maint as you can see is a value set to a field in
the recordset, as is Veh_ID. I do not understand why Veh_ID works but Maint
does not. When I run the code, a popup prompts me for a value for 'none'
(which is the actual value of the Maint variable). Please help! This code
is going to have more to it, but I need this part to work first. Thanks
Anthony
trying to use:
Dim rs As DAO.Recordset
Dim strSql As String
strSql = "Select [Recommendations].Vehicle_ID, IIF
(category=121,RecommendText,'none') AS Box1, IIF
(category=146,RecommendText,'') AS 146, IIF(category=109,RecommendText,'')
AS 109, IIF(category = 148,RecommendText,'') AS 148, IIF
(category=149,RecommendText,'') AS 149, IIF(category=130,RecommendText,'')
AS 130, IIF(category=129,RecommendText,'') AS 129, IIF
(category=115,RecommendText,'') AS 115, IIF(category=120,RecommendText,'')
AS Box9, IIF(category=124,RecommendText,'') AS 124 FROM [Recommendations]
INNER JOIN [Category] ON [Recommendations].category=[Category].Code;"
' strSql = "Select Vehicle_ID from [Recommendations];"
Set rs = CurrentDb.OpenRecordset(strSql)
' process untill end of file
Do While rs.EOF = False
' Value Set for Testing Purposes here
If rs!Vehicle_ID = 1874 Then
' Showing Values Only For Testing
MsgBox _
rs!Vehicle_ID
Dim Veh_ID As String
Dim Maint As Variant
Maint = rs!Box1
Veh_ID = rs!Vehicle_ID
MsgBox _
[Veh_ID]
MsgBox _
[Maint]
Dim Sql As String
Sql = "Update [Recommendations_Master] set Recommendations_Vehicle_ID = "
& Veh_ID & _
", 120 = " & Veh_ID & _
", 121 = " & 121 & ";"
DoCmd.RunSQL (Sql)
rs.MoveNext
Else
rs.MoveNext
End If
Loop
rs.Close
The problem is in the update Sql. Two problems. The code is correct in
putting in the value for Veh_ID, but not for Maint or 121. 121 is a direct
field from the recordset. Maint as you can see is a value set to a field in
the recordset, as is Veh_ID. I do not understand why Veh_ID works but Maint
does not. When I run the code, a popup prompts me for a value for 'none'
(which is the actual value of the Maint variable). Please help! This code
is going to have more to it, but I need this part to work first. Thanks
Anthony