Invalid SQL Statement - View Northwind.mdb

G

Guest

Hi all,

I am new in VBA Programming on my Access 2003 of Office 2003 that is built
on Windows XP Pro-Microsoft NT 4. I got a Run-Time error
'2147217900(80040e14):
Invalid SQL statement: expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT',
or 'UPDATE', when I executed the attached progrm. The Debug points on the
statement 'rest1.Open "AllEmployees", cnn1'. This error message does not
make sense to me. Please help and advise me what is wrong with the program
and how to solve the problem.
Thankls in advance,
SHC
/////////////////////////////////////
Sub ViewAView()
Dim cnn1 As New ADODB.Connection
Dim rst1 As New ADODB.Recordset
Dim intMaxLength As Integer, Length As Integer, strFiller As Integer

' Open the connection.
cnn1.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Program Files\Microsoft
Office\Office11\Samples\Northwind.mdb;"

'Find the longest name.
rst1.Open "AllEmployees", cnn1
Do Until rst1.EOF
Length = Len(rst1.Fields("FirstName")) + _
Len(rst1.Fields("LastName"))
If Length > intMaxLength Then intMaxLength = _
Length
rst1.MoveNext
Loop

'Print first name, last name, and third field.
rst1.MoveFirst
Do Until rst1.EOF
strFiller = (intMaxLength + 2) - _
(Len(rst1.Fields("FirstName")) + _
Len(rst1.Fields("LastName")))
Debug.Print rst1.Fields("FirstName") & " " & _
rst1.Fields("LastName") & String(strFiller, " ") & _
rst1.Fields(2)
rst1.MoveNext
Loop

End Sub
 
G

George Nicholson

I don't see a table or query named "AllEmployees" in my copy of Northwind
for 2003 (or 2002).

Is this something you added yourself, or the cause of the error?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top