XL VBA SQL Syntax

HKFuey
HKFuey used Ask the Experts™
on
I am using SQL to query a database (SQL 2000) in XL: -

sql = "SELECT InvMaster.StockCode, InvMaster.Description "
sql = sql & "FROM InvMaster "
sql = sql & "WHERE (((InvMaster.StockCode)=" & ActiveCell & "))"

It falls over because the ActiveCell is 'DYN/COM' (with a forward slash)

Does anyone know the syntax to get round this?

Going home now but will chack back Monday ; )

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
sql = "SELECT InvMaster.StockCode, InvMaster.Description "
sql = sql & "FROM InvMaster "
sql = sql & "WHERE (((InvMaster.StockCode)='" & ActiveCell & "'))"

Encircle the variable in ' as above.
sql = "SELECT InvMaster.StockCode, InvMaster.Description "
sql = sql & "FROM InvMaster "
sql = sql & "WHERE (((InvMaster.StockCode)=" & char (39) & ActiveCell & char (39) & "))"
chr (39), sorry.

Author

Commented:
Thanks, both work but Cluskit was first so more points ; )

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial