SQL help

catalpa

New Member
Joined
Jun 13, 2004
Messages
11
Hello,

I am trying to run a query from an Excel macro. I found this query by viewing a query from the query editor in Access in SQL view. This is what I got (with double quotes put around the name of the text I'm querying for):

string = "SELECT table.column1, table.column2 FROM table WHERE ((table.column1)=""value""));"

However, when I try to run this query, I get the error "Invalid column name "value"."

I have also tried the following variations:

string = "SELECT table.column1, table.column2 FROM table WHERE ((table.column1) Like ""value""));"

string = "SELECT table.column1, table.column2 FROM table WHERE table.column1=""value"";"

string = "SELECT table.column1, table.column2 FROM table WHERE (table.column1=""value"");"

string = "SELECT table.column1, table.column2 FROM table WHERE table.column1='value';"

string = "SELECT table.column1, table.column2 "
string = string & " FROM table"
string = string & " WHERE (((table.column1)=""value""));"

Can anyone tell what I am doing wrong?

thanks in advance,

catalpa
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Hi catalpa, change table to tbl (or else) of the Table name of the Access file.

Code:
Sub GetDataFromMdb()
'Need reference DAOx.x Object Library
    Dim myDB As Database, myRS As Recordset, sql As String
     
    Set myDB = OpenDatabase("C:\db1.mdb")
    sql = "SELECT column1,column2 FROM tbl WHERE column1 ='VALUE'"
    Set myRS = myDB.OpenRecordset(sql)
    Worksheets("sheet1").Range("A1").CopyFromRecordset myRS
    myRS.Close
    myDB.Close
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,691
Members
448,978
Latest member
rrauni

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top