Connecting Tech Pros Worldwide Help | Site Map

Syntax error....

Newbie
 
Join Date: Jan 2008
Posts: 19
#1: Feb 17 '09
I have this code:
Expand|Select|Wrap|Line Numbers
  1. Set rs = db.OpenRecordset("SELECT * FROM expressions order by heb WHERE '" & TextBox2.Text & "' = InStr(![heb], TextBox1.Text)")
Can someone show me where the syntax error is and what is the correct way to write this line?

I am desperate!!! :-(
Moderator
 
Join Date: Feb 2008
Location: Beauly, near Inverness, Scotland
Posts: 1,576
#2: Feb 17 '09

re: Syntax error....


This post appears to be a duplicate of post 25 of this thread, a thread which is now closed to your satisfaction. Please do not double-post your questions as this wastes the time of the experts involved.

You also provide no clue as to what error you are getting or the context of whatever 'this code' is.

A revised version of your code which may have more of a chance of working is shown below.

Expand|Select|Wrap|Line Numbers
  1. Set rs = db.OpenRecordset("SELECT * FROM expressions WHERE [" & TextBox2.Text & "] = " & InStr(![heb], TextBox1.Text) & " ORDER BY heb;")
I'd be surprised if just getting the syntax right means it will work straight away, however, as it may be OK for syntax and still not mean anything to Access...

-Stewart
Newbie
 
Join Date: Jan 2008
Posts: 19
#3: Feb 17 '09

re: Syntax error....


The code is now working beautifully.... I hope I won't have to eat my hat later on... but it's working for now.

Thank you for your reply.

Iris
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,703
#4: Feb 17 '09

re: Syntax error....


Expand|Select|Wrap|Line Numbers
  1. = InStr(![heb], ...
is likely to suffer too, as you have an orphaned bang (!) within your SQL string. This syntax is only valid within a With clause of VBA. Not in SQL.
Newbie
 
Join Date: Jan 2008
Posts: 19
#5: Feb 17 '09

re: Syntax error....


![heb] - to -
instr(heb, '" & TextBox1.Text & "')

so it's OK.

Thank you for your kindness and for your caring.

Have a great day!

Iris
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,703
#6: Feb 17 '09

re: Syntax error....


No worries,

and Welcome to Bytes!
Reply