Results 1 to 5 of 5

Thread: Moving in a recordset

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2000
    Location
    Montana
    Posts
    6

    Post

    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

  2. #2
    Hyperactive Member Gimpster's Avatar
    Join Date
    Oct 1999
    Location
    Redmond, WA 98052
    Posts
    331

    Post

    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
    -Ryan
    I smell varmint poontang, and the only good varmint poontang is dead varmint poontang...

    -Bill Murray, Caddyshack

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2000
    Location
    Montana
    Posts
    6

    Post

    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

  4. #4
    Hyperactive Member Gimpster's Avatar
    Join Date
    Oct 1999
    Location
    Redmond, WA 98052
    Posts
    331

    Post

    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.
    -Ryan
    I smell varmint poontang, and the only good varmint poontang is dead varmint poontang...

    -Bill Murray, Caddyshack

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2000
    Location
    Montana
    Posts
    6

    Post

    Yes, this is a DHTML application. It seems that this does add another level of complexity! Thanks for the followup...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width