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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBScript MS Access SQL statement Query HELP

Status
Not open for further replies.

Broozer

Technical User
Jan 5, 2007
4
US
Problem with send a MS Access SQL Query with a client side string variable using VBscript. I use the client side to dim my variable, but when I try using this variable in a sql statement in server side code it fails. I have used msgbox on the client side to debug and I see the statement but the variable is blank or if I use "'" "'" around my variable I get 'variable' and no value of the variable. BUT I can use a number 111 and the sql statment works can somebody help me. THIS HAS GONE ON TOO LONG
COPY OF MY CODE

<Script Language="VBscript">

dim conn2
dim rs2
dim sql
dim v_compID

Document.select.T1.value = "222"
v_compID = Document.select.T1.value


<% Set conn2 = Server.CreateObject("ADODB.Connection") %>
<% conn2.Open "DSN=TimeData" %>
<% Set rs2 = Server.CreateObject("ADODB.Recordset") %>
<% Set rs2.ActiveConnection = conn2 %>

<% sql = "SELECT * FROM Companys WHERE Company ='" & v_compID & "'" %>

<% rs2.Open sql, conn2, 0, 4 %>
msgbox " <%= sql %>"
<% Do while NOT rs2.EOF %>

Document.ComboBox2.AddItem("<%= rs2("Cid") %> " & " " & "<%= rs2("Company") %>")

<% rs2.MoveNext %>
<% Loop %>

<% rs2.close %>
<% conn2.close %>

</SCRIPT>
 
It's not an SQL issue but an ASP one.
You can't reference a client side variable in server side code this way ...
You'll get more accurate answers in the ASP forum.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Leslie my data type is text in the database.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top