Results 1 to 3 of 3

Thread: Code to display contents of a table from a database

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2001
    Location
    Botswana
    Posts
    21

    Question Code to display contents of a table from a database

    Hie...

    I am looking for a code to perform the following:

    1. Created a database with the table IT_COMPANIES having the fields compid, compname, dtestablished etc. The table has 100 records.

    2. Created a form IT HISTORY with a button btnmoredetails, on clicking the button, the table IT_COMPANIES should be opened, but displaying the first 10 records. Now in this case the table should have the next and previous buttons to navigate to the next or last 10 records.

    Please help me with a code that will perform the tasks in step two.
    Genie

  2. #2
    Frenzied Member seoptimizer2001's Avatar
    Join Date
    Apr 2001
    Location
    Toledo, Ohio USA GMT -5
    Posts
    1,075
    Code:
    ''Do this in form declarations
    Dim cn as New ADODB.Connection
    Dim rs as New ADODB.RecordSet
    Dim sql as String
    
    ''Button click event
    Private Sub Command1_Click()
    sql = "select * from IT_Companies order by "whatever you want"
    
    cn.Open("your connection string")
    rs.CursorType = adOpenDynamic
    Set rs = cn.Execute(sql)
    
    Call Next10
    
    End Sub
    
    Sub Next10()
    Dim i as Integer
    
    While i < 10 and Not rs.EOF
      'put the information wherever you want it
      rs.Movenext
       i = i + 1
    Wend
    
    End Sub
    
    Sub Previous10()
    Dim i as Integer
    
    While i < 10 and Not rs.BOF
      'put the information wherever you want it
      rs.MovePrevious
       i = i + 1
    Wend
    
    End Sub
    
    Private Sub cmdNext_Click()
    
    Call Next10
    
    End Sub
    
    Private Sub cmdPrevious_Click()
    
    Call Previous10
    
    End Sub
    Make sure you reference the MS ADO 2.5 Library

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Aug 2001
    Location
    Botswana
    Posts
    21

    Your code

    Thank you, i'll try your code and will get back to u if i have a problem
    Genie

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