• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 904
  • Last Modified:

DoCmd.RunSQL

I have a form in MS Access 2000. In the form I have a combo box that passes the variables to a SQL statement I want to execute:
   
Dim SQL As String
   
    SQL = "SELECT dbo_string.StringID, dbo_string.StringCode, dbo_string.NeutralValue, dbo_stringlocalized.LocalizedValue "
    SQL = SQL & "FROM dbo_string INNER JOIN dbo_stringlocalized ON dbo_string.StringCode = dbo_stringlocalized.StringCode "
    SQL = SQL & "WHERE (((dbo_string.stringcode) = [dbo_stringlocalized].[stringcode]) And ((dbo_string.ActiveFlag) = 1) "
    SQL = SQL & "And ((dbo_string.LocalizeFlag) = 1) And ((dbo_stringlocalized.ActiveFlag) = 1)) "
    SQL = SQL & "AND ((dbo_stringlocalized.LocaleLanguageCountryIdentifier)= " & Combo0.Value & ")"
   
DoCmd.RunSQL SQL

The last line gives me an error: "A RunSQL action requires an argument consisting of an SQL statement."

I just want to output the results to the screen.

Thanks
0
ebtech
Asked:
ebtech
1 Solution
 
shanesuebsahakarnCommented:
RunSQL needs an action query (ie an INSERT, APPEND or DELETE sql satement) rather than a SELECT statement.

To output the query to screen, try this:
First of all, create a query (it doesn't matter what the query does) and save it, call it something like qryTemp.

Next, instead of the RunSQL line, try this:
CurrentDb.QueryDefs("qryTemp").SQL = SQL
DoCmd.OpenQuery "qryTemp"

You'll need a reference to DAO - open a code module, click Tools->References and make sure Microsoft DAO 3.6 is checked. That should do what you need.
0
 
ebtechAuthor Commented:
This works great, thanks
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now