darrenhubbard
Technical User
Hi All,
I have the following VBA function:
Private Sub TrafficButton_Click()
Param = [Forms]![VAD]![TableSelect]
If IsNull(Param) Then
MsgBox "Please select a table from the drop-down list"
Exit Sub
End If
Param = Trim("[" & Trim(Param) & "]"
MsgBox Param
querystring = "SELECT " & Param & ".LastOccurence, Applications.Application, ApplicationNames.[Application Name], " & Param & ".[Server IP], " & Param & ".[Server Port], " & Param & ".Protocol, " & Param & ".[Client IP], " & Param & ".ServerTotal, " & Param & ".ClientTotal, " & Param & ".TotalNumber FROM (" & Param & " LEFT JOIN Applications ON (" & Param & ".[Server Port]=Applications.[Server Port]) AND (" & Param & ".Protocol=Applications.Protocol)) LEFT JOIN ApplicationNames ON (" & Param & ".[Server Port]=ApplicationNames.[Server Port]) AND (" & Param & ".Protocol=ApplicationNames.Protocol) AND (" & Param & ".[Server IP]=ApplicationNames.[Server IP]) ORDER BY [ServerTotal] DESC;"
MsgBox querystring
DoCmd.SetWarnings False
DoCmd.RunSQL Trim(querystring)
DoCmd.SetWarnings True
Exit Sub
End Sub
The function runs when a button on a form is clicked and it takes the name selected from a ComboBox into "Param"
The two msgbox's are there for my debugging purposes and the all the "trim"'s are there because I'm paranoid
For some reason, the DoCmd.RunSQL generates the error message "A RunSQL action requires an argument consisting of an SQL statement".
I've even copied the value of querystring that RunSQL is trying to execute into a query and it runs absolutely fine and as intended.
Anybody got any ideas?
Thanks for all your help,
Darren
I have the following VBA function:
Private Sub TrafficButton_Click()
Param = [Forms]![VAD]![TableSelect]
If IsNull(Param) Then
MsgBox "Please select a table from the drop-down list"
Exit Sub
End If
Param = Trim("[" & Trim(Param) & "]"
MsgBox Param
querystring = "SELECT " & Param & ".LastOccurence, Applications.Application, ApplicationNames.[Application Name], " & Param & ".[Server IP], " & Param & ".[Server Port], " & Param & ".Protocol, " & Param & ".[Client IP], " & Param & ".ServerTotal, " & Param & ".ClientTotal, " & Param & ".TotalNumber FROM (" & Param & " LEFT JOIN Applications ON (" & Param & ".[Server Port]=Applications.[Server Port]) AND (" & Param & ".Protocol=Applications.Protocol)) LEFT JOIN ApplicationNames ON (" & Param & ".[Server Port]=ApplicationNames.[Server Port]) AND (" & Param & ".Protocol=ApplicationNames.Protocol) AND (" & Param & ".[Server IP]=ApplicationNames.[Server IP]) ORDER BY [ServerTotal] DESC;"
MsgBox querystring
DoCmd.SetWarnings False
DoCmd.RunSQL Trim(querystring)
DoCmd.SetWarnings True
Exit Sub
End Sub
The function runs when a button on a form is clicked and it takes the name selected from a ComboBox into "Param"
The two msgbox's are there for my debugging purposes and the all the "trim"'s are there because I'm paranoid
For some reason, the DoCmd.RunSQL generates the error message "A RunSQL action requires an argument consisting of an SQL statement".
I've even copied the value of querystring that RunSQL is trying to execute into a query and it runs absolutely fine and as intended.
Anybody got any ideas?
Thanks for all your help,
Darren