Invalid SQL statement on rst.Open to same table in 'Current' event

W

WDSnews

I have a 12 record table called Color Values and a form called Color Values.
The form has twelve boxes which I wish to color according to the R, G, and B
values in the table. Each box is to display a different color based on the
record it represents. I'm using the 'Current' event to color the twelve
boxes so the twelve colors can be seen side-by-side. My strategy is to open
a recordset to the same table the form is bound to. Although I've borrowed
this code from one of my other forms, it gives me an error on this form.

Here's the error....

Run-time error '-2147217900 (80040e14)':
Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE',
'SELECT', or 'UPDATE'.

Here's my code which causes the error....

Private Sub Form_Current()
Dim cnnColor As ADODB.Connection
Dim rstColor As ADODB.Recordset

Set cnnColor = Application.CurrentProject.Connection
Set rstColor = New ADODB.Recordset

' get Colors
rstColor.Open Source:="Color Values", ActiveConnection:=cnnColor, _
CursorType:=adOpenKeyset, LockType:=adLockPessimistic

Why is the code giving me an error on this form? I welcome your suggestions
and thank you very much.
 
D

Daryl S

WDSnews -

I suspect your table name needs square brackets since there is a space in
it. "[Color Values]"
 
W

WDSnews

thank you. You're probably correct. I implemented a recordset clone as a
work around. However, your solution would be better since I'd prefer ADO and
SQL type solutions. Thanks for your help.



Daryl S said:
WDSnews -

I suspect your table name needs square brackets since there is a space in
it. "[Color Values]"

--
Daryl S


WDSnews said:
I have a 12 record table called Color Values and a form called Color
Values.
The form has twelve boxes which I wish to color according to the R, G,
and B
values in the table. Each box is to display a different color based on
the
record it represents. I'm using the 'Current' event to color the twelve
boxes so the twelve colors can be seen side-by-side. My strategy is to
open
a recordset to the same table the form is bound to. Although I've
borrowed
this code from one of my other forms, it gives me an error on this form.

Here's the error....

Run-time error '-2147217900 (80040e14)':
Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE',
'SELECT', or 'UPDATE'.

Here's my code which causes the error....

Private Sub Form_Current()
Dim cnnColor As ADODB.Connection
Dim rstColor As ADODB.Recordset

Set cnnColor = Application.CurrentProject.Connection
Set rstColor = New ADODB.Recordset

' get Colors
rstColor.Open Source:="Color Values", ActiveConnection:=cnnColor, _
CursorType:=adOpenKeyset, LockType:=adLockPessimistic

Why is the code giving me an error on this form? I welcome your
suggestions
and thank you very much.


.
 

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