Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What is going wrong with this ADO code? 1

Status
Not open for further replies.

BTilson

Programmer
Jul 14, 2004
139
0
0
US
I've written code like this quite a few times, but all of a sudden this code is throwing an error message. The error message is this:

Run-time error '-2147217900 (80040x14)':

Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE'.

The code generating this is as follows:
----------------------------------------------------------------------
Public Function test()

Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset

Set cnn = CurrentProject.Connection
Set rst = New Recordset

rst.Open "Scrap Tickets", cnn, adOpenDynamic, adLockOptimistic

rst.MoveFirst

While Not rst.EOF

Debug.Print rst.Fields(0).Value

rst.MoveNext

Wend

rst.Close
Set rst = Nothing

Debug.Print "finished"

End Function
----------------------------------------------------------------------

The line: "rst.Open "Scrap Tickets", cnn, adOpenDynamic, adLockOptimistic" is what is generating the error message. "Scrap Tickets" is a table located in the same database that I am writing this module in.

I feel like I'm probably missing something very simple here, but I can't figure out what is going on, especially since this code is directly based off of working code I'd already written.

Anyone have any ideas?

Thanks in advance for your time!

Brooks Tilson
Database Development
Tilson Machine, Inc.
 
What about this ?
rst.Open "SELECT * FROm [Scrap Tickets]", cnn, adOpenDynamic, adLockOptimistic

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
rst.Open "Scrap Tickets", cnn, adOpenDynamic, adLockOptimistic, adCmdTable

 
PHV is spot on. If your table/query name contains spaces, you must enclose it in brackets.

“Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family.” (Kofi Annan)
Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.
 
Thanks everyone! I just took the space out of the name and it fixed it right up.

Brooks Tilson
Database Development
Tilson Machine, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top