syntax error?

G

GM

I keep getting an invalid error message when running this code:
(I added two stars to highlight the part that gives the invalid error message)

Set rstclass = New ADODB.Recordset
rstclass.CursorLocation = adUseClient
**rstclass.Open "select * from " & recsource & "where id = '" &
Me.Form.ID.Value & "', CurrentProject.Connection, adOpenKeyset,
adLockOptimistic"**
Set cSpace.DataSource = rstclass
cSpace.hasmultiplecharts = False
cSpace.setdata c.chdimvalues, c.chdatabound, Array("id", "wpm")

I'm trying to link a chart--cSpace--on my form to show updated info from the
current recordset. I'm not trying to open a new window displaying a chart.

Thanks for any ideas....
 
D

Douglas J. Steele

What data type is Id? The way you've got it coded, it must be text. If it's
numeric, lose the single quotes.
 
O

Ofer

If the Id is string type, then try this

rstclass.Open "select * from " & recsource & "where id = '" &
Me.Form.ID.Value & "'", CurrentProject.Connection, adOpenKeyset,
adLockOptimistic

If the Id is Number then try this
rstclass.Open "select * from " & recsource & "where id = " &
Me.Form.ID.Value, CurrentProject.Connection, adOpenKeyset,
adLockOptimistic
 
G

GM

Thank you both, Ofer, and Doug, for your suggestions. I tried both ways but
still have an error. The error now says missing operator in query expression
fromwhere id = 1.

ID is a numeric value referencing the primary index of each recordset.
 
M

Marshall Barton

GM said:
Thank you both, Ofer, and Doug, for your suggestions. I tried both ways but
still have an error. The error now says missing operator in query expression
fromwhere id = 1.

ID is a numeric value referencing the primary index of each recordset.
[snip]

The "FromWhere" part of the message implies that the value
of recsource is Null. It's also telling you taht the is a
missing space in fromt of the word Where.
 
O

Ofer

Sorry, should hae noticed that

Me.Form.ID.Value
If the Id is on the main form, then use that
Me.ID

If the Id is in a sub form, then
Me.[SubFormControlName].Form.ID
--
If I answered your question, please mark it as an answer. That way, it will
stay saved for a longer time, so other can benifit from it.

Good luck
 
Top