stevethefiend
New member
- Local time
- Today, 13:53
- Joined
- Jan 18, 2007
- Messages
- 3
Hello, i am having some issues with an sql statement not running that has been built upo dynamically in code:
Private Sub cmdSave_Click()
Text8.SetFocus
StrDescription = Text8.Text
Text10.SetFocus
StrParent = Text10.Text
Text12.SetFocus
StrPIN = Text12.Text
Text14.SetFocus
StrDWG = Text14.Text
Text16.SetFocus
StrComment1 = Text16.Text
Text18.SetFocus
StrOldTag = Text18.Text
Text20.SetFocus
StrOldDWG = Text20.Text
Text22.SetFocus
StrComment2 = Text22.Text
Dim StrSQL As String
StrSQL = "UPDATE [" & StrUnit & " Instrumentation] SET [Description] = '" & StrDescription & "', [Parent] = '" & StrParent & "', [Plant Item No: PIN] = '" & StrPIN & "', [Dwg No:] = '" & StrDWG & "', [Comments / Issued To By] = '" & StrComment1 & "', [Old Tag ID] = '" & StrOldTag & "', [Old Dwg No:] = '" & StrOldDWG & "', [Comment] = '" & StrComment2 & "' WHERE [Inst ID] like '" & StrInstID & "' AND [Item No:] like '*" & StrItemNo & "*'"
If StrItemID <> vbNullString Then
StrSQL = StrSQL & " AND [Item ID] like '*" & StrItemID & "*'"
End If
If StrItemID <> "" Then
StrSQL = StrSQL & " AND [Item ID] like '*" & StrItemID & "*'"
End If
If StrItemID = "" Then
StrSQL = StrSQL & " AND ([Item ID] is null Or [Item ID] like '')"
End If
Debug.Print StrSQL
Dim cmd1 As ADODB.Command
Set cmd1 = New ADODB.Command
cmd1.ActiveConnection = CurrentProject.Connection
cmd1.CommandText = StrSQL
cmd1.Execute
DoCmd.Close
End Sub
i have very similar code to this elsewhere in the application that works fine and when i run the sql query that gets spat out into the debug window it all goes as planned. it just doesnt execute, i have tried re-structuring the code in a variety of ways and am at a loss if anyone can help please please post
Private Sub cmdSave_Click()
Text8.SetFocus
StrDescription = Text8.Text
Text10.SetFocus
StrParent = Text10.Text
Text12.SetFocus
StrPIN = Text12.Text
Text14.SetFocus
StrDWG = Text14.Text
Text16.SetFocus
StrComment1 = Text16.Text
Text18.SetFocus
StrOldTag = Text18.Text
Text20.SetFocus
StrOldDWG = Text20.Text
Text22.SetFocus
StrComment2 = Text22.Text
Dim StrSQL As String
StrSQL = "UPDATE [" & StrUnit & " Instrumentation] SET [Description] = '" & StrDescription & "', [Parent] = '" & StrParent & "', [Plant Item No: PIN] = '" & StrPIN & "', [Dwg No:] = '" & StrDWG & "', [Comments / Issued To By] = '" & StrComment1 & "', [Old Tag ID] = '" & StrOldTag & "', [Old Dwg No:] = '" & StrOldDWG & "', [Comment] = '" & StrComment2 & "' WHERE [Inst ID] like '" & StrInstID & "' AND [Item No:] like '*" & StrItemNo & "*'"
If StrItemID <> vbNullString Then
StrSQL = StrSQL & " AND [Item ID] like '*" & StrItemID & "*'"
End If
If StrItemID <> "" Then
StrSQL = StrSQL & " AND [Item ID] like '*" & StrItemID & "*'"
End If
If StrItemID = "" Then
StrSQL = StrSQL & " AND ([Item ID] is null Or [Item ID] like '')"
End If
Debug.Print StrSQL
Dim cmd1 As ADODB.Command
Set cmd1 = New ADODB.Command
cmd1.ActiveConnection = CurrentProject.Connection
cmd1.CommandText = StrSQL
cmd1.Execute
DoCmd.Close
End Sub
i have very similar code to this elsewhere in the application that works fine and when i run the sql query that gets spat out into the debug window it all goes as planned. it just doesnt execute, i have tried re-structuring the code in a variety of ways and am at a loss if anyone can help please please post