Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using VBA with SQL 1

Status
Not open for further replies.

scroce

MIS
Nov 30, 2000
780
US
Let's say you have:

Dim strSQL as String
Dim MyVar as String

strSQL = "DELETE tblChosenOnes.ChosenOnes FROM tblChosenOnes WHERE (((tblChosenOnes.ChosenOnes)='fred'));"

I know that the above SQL actually works, BUT I do not want 'Fred' to be static. I want the user to be able to change 'Fred' thru a list box.

SO:

How do you replace 'fred' with a variable (MyVar)so that you won't get an SQL error? - or can you even do this at all? i.e. what's the syntax?

thanks.

<b>s.c.</b>
 
I hope this is helpful:

Dim strSQL as String
Dim MyVar as String

MyVar = &quot;Fred&quot; 'or however else you set it

strSQL = &quot;DELETE tblChosenOnes.ChosenOnes FROM tblChosenOnes WHERE (((tblChosenOnes.ChosenOnes)='&quot; & MyVar & &quot;'));&quot;



 
Hi,
Here is the syntax:

strSQL = &quot;DELETE tblChosenOnes.ChosenOnes FROM tblChosenOnes WHERE (((tblChosenOnes.ChosenOnes)='&quot; & MyVar & &quot;'));&quot;

However, &quot;DELETE tblChosenOnes.* FROM....&quot; looks better.

Rob Marriott
rob@career-connections.net
 
Seems like evertime I post answers recently... someone posts the same answer at the same time that I do! AAAHHH! =)

Rob Marriott
rob@career-connections.net
 
thanks. that was it. syntax was driving me crazy!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top