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

Query always returns a null ?

Status
Not open for further replies.

allyeric

Programmer
Mar 14, 2000
104
CA
I am accessing an Access 2000 database with VB6.&nbsp;&nbsp;My problem:&nbsp;&nbsp;when I use the query (as below), it returns a null value, even if there is data in that record.&nbsp;&nbsp;Actually, it does return a value, but once the program passes the set statement, the value turns into a null.&nbsp;&nbsp;What I am trying to do is see if there is data in that field, and if there is, put that value into a text box, but if there is not, then put a &quot;&quot; value into the textbox.&nbsp;&nbsp;Here is my code, I hope someone can help me.&nbsp;&nbsp;Thanks&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br><br><br>strSQL = &quot;SELECT * from Answers where No_Employe = &quot; & frmPassword.txtEmpNo.Text<br>Set con = New ADODB.Connection<br>con.Open &quot;DSN=Training;UID=;PWD=;&quot;<br>Set rs = con.Execute(strSQL)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If rs(&quot;Ques_&quot; & (Index)) &lt;&gt; &quot;&quot; Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;txtAnswer.Text = rs(&quot;Ques_&quot;&nbsp;&nbsp;(Index))&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Else<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;txtAnswer.Text = &quot;&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;End If<br><br><br>in my database, I have &quot;Allow Zero Length&quot; as yes<br><br><br>
 
you haven't used string delimiters for your variable<br>try:<br>strSQL = &quot;SELECT * from Answers where No_Employe = '&quot; & frmPassword.txtEmpNo.Text & &quot;'&quot;<br><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top