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

Query returns 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>
 
If No_Employe is not a numeric field in the database, you'll need to enclose it within quotes in the query.<br><br>From the code you posted, the Variable Index is not assigned a value.&nbsp;&nbsp;Assuming it's declared as a numeric field, it will always be 0.&nbsp;&nbsp;Do you have a Ques_0 field in the database?<br><br>You should also check for nulls before referencing a field that could have a null value.<br> <p>nick bulka<br><a href=mailto:nick@bulka.com>nick@bulka.com</a><br><a href= > </a><br>
 
thanks for your reply.&nbsp;&nbsp;The Variable Index is initialized with a value of 1, and gets incremented.&nbsp;&nbsp;No_Employe is a numeric field.&nbsp;&nbsp;<br><br>The thing is, when I do the debug, when it sets rs, the value is correct.&nbsp;&nbsp;But, as it moves on to the If statement, it changes to a null value.&nbsp;&nbsp;&nbsp;This seems very strange to me.&nbsp;&nbsp;I sure hope someone can help!
 
turn off all error checking,&nbsp;&nbsp;and run the program.&nbsp;&nbsp;I expect there's an error that you're not trapping.&nbsp;&nbsp;An if statement can't change the value of a variable. <p>nick bulka<br><a href=mailto:nick@bulka.com>nick@bulka.com</a><br><a href= > </a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top