-
I have a text box that I want to tie to a recordset. How can I do this and then navigate through the recordset?
I have been able to make the textbox display the first field in the recordset, but I can't seem to get it to display the rest of the fields. I have tried to use .movenext, but I must be doing something wrong.
Any suggestions?
Thanks, Stephen
-
No, you have the right idea. But let me guess as to what you did since you didn't post your code. You probably defined the recordset, opened it, and then did something like this
Text1.Text = Rs1.Fields("field_name").Value
to set the information stored in the table as the text in the textbox. Well, all you need to do is after you move to the next record, set the text again. So you would have some code similar to this:
Code:
Rs.Source = "SELECT * FROM Temp_Table"
Rs.Open , , adOpenDynamic
Rs.MoveFirst
Text1.Text = Rs.Fields("field_name").Value
Rs.MoveNext
Text1.Text = Rs.Fields("field_name").Value
So my guess as to what your problem is, is that you aren't setting the text of the textbox after you move to the next record. However, I cannot say for sure since you didn't post your code. Hope this helps. And if not, just post your code on this same topic.
Edited by Gimpster on 03-08-2000 at 05:17 PM
-
Thanks for the reply, this is definitely pointing me in the right direction.
I put the code in as you wrote it, and had to modify it a tad as you'll see below. When I put the code in together, it automatically displayed the second record. I moved the rs.next section, and then it showed the first record. I decided to create a command button to make it go to the next record. For some reason, it didn't work. Could you take a look at my code to see what's wrong with it?
When I click on my next button, I get a debug error highlighting my rs.MoveNext line.
Private Function btnNext_onclick() As Boolean
rs.MoveNext
TextField1.Value = rs.Fields("Technician").Value
End Function
Private Sub DHTMLPage_Load()
'set variables
Dim cnn1 As ADODB.Connection
Dim cmdSQL As ADODB.Command
Dim strCnn As String
Dim strSQL As String
Dim varTechnician As Variant
Dim rs As ADODB.Recordset
'Open Connection
Set cnn1 = New ADODB.Connection
'set connection strings
strCnn = "Provider=SQLOLEDB.1;" & _
"Persist Security Info=False;User ID=sa;" & _
"Initial Catalog=Help_Desk;Data Source=BRC_NT_NX"
'open the connection
cnn1.Open strCnn
' Open a recordset based on a SQL query.
Set rs = New ADODB.Recordset
strSQL = "Select * From Technicians"
rs.Open strSQL, strCnn, , adCmdText
rs.MoveFirst
TextField1.Value = rs.Fields("Technician").Value
End Sub
-
It looks to me like you're trying to code a web page. Is that correct? Because if you are, then I think some of the things I've told you will not work, because the coding is different.
-
Yes, this is a DHTML application. It seems that this does add another level of complexity! Thanks for the followup...