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

Writing SQL results to a textbox 1

Status
Not open for further replies.

wonghei7

Technical User
Jun 7, 2003
9
SG
Hi. I'm trying to write the sql results to a textbox for display. My codes are as follows to retrieve the value via sql. However, i'm having trouble writing the results to the textbox. Can anyone help?

Private Sub Form_Load()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset

Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset

With cn
.Provider = "Microsoft.jet.oledb.4.0"
.CursorLocation = adUseClient
.ConnectionString = App.Path + "\Quotation.mdb"
.Open
End With

rs.Open "select [productcode] from products where ([productname]='" & Label14.Caption & "'),cn,adopenkeyset"

rs.Close
End Sub
 
After the Rs.Open do this:

Text1.Text = ""
Do While Not rs.eof
Text1.Text = Text1.Text & rs("productcode").value & vbcrlf
rs.movenext
Loop


Rob
 
Hi Rob, thanks for the reply. I just tried and I can an error saying "member or data member not found". It highlights .Text=

 
I did. After I typed the . after my textbox, i only get to choose .count, .item, .lbound and .ubound. I also tried text1.item.text=" " but then i get another error saying "argument not optional". really at a lost now.
 
Make sure it is a text box and not a label. Label is .Caption

Hope this helps,
Daisy
 
It's an array of textboxes.

Do you want the results to go to one textbox or do you wabt each record to have it's own textbox?



Rob
 
Try this:

Dim count as integer
count = 0
Do While Not rs.eof
if count <> 0 then
Load text1(count)
text1(count).top = text1(count-1).top + 300
End if
text1(count).visible = true
text1(count).Text = rs(&quot;productcode&quot;).value
rs.movenext
Loop


Rob
 
Oh, thank you so much Rob. It works! Thanks again.

Elis
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top