SQL query and VBA

Hakum
Hakum used Ask the Experts™
on
Hi guys, Im trying to figur out a Query and im not that strong in SQL querys at all.. please advise

From Excel with a Ado. connection ( which works just fine) i need something like:

Select * FROM Tblname WHERE [namecol] = "'" & Name & "'" AND WHERE [Workcol] = "'" & work &"'"

Then msgbox result

Please advise

Thank you in advance
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
IT Engineer
Distinguished Expert 2017
Commented:
You just need a WHERE clause:
Select * FROM Tblname WHERE [namecol] = "'" & Name & "'" AND [Workcol] = "'" & work &"'" 

Open in new window

Jim HornSQL Server Data Dude
Most Valuable Expert 2013
Author of the Year 2015
Commented:
For starters, lose the second WHERE

Select * FROM Tblname WHERE [namecol] = "'" & Name & "'" AND WHERE [Workcol] = "'" & work &"'"
should be
Select * FROM Tblname WHERE [namecol] = "'" & Name & "'" AND [Workcol] = "'" & work &"'"
John TsioumprisSoftware & Systems Engineer
Commented:
Select * FROM Tblname WHERE [namecol] = '" & Name & "' AND [Workcol] = '" & work & "' 

Open in new window

Top Expert 2009
Commented:
Name is a reserved word, so it is not advisable to use it as a variable name.

Author

Commented:
Thanks Guys, i found out that I was right from start but VBA has a bug when counting ther recordset :)

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