Results 1 to 6 of 6

Thread: Why dosent this 5 line code work???

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2000
    Location
    London, UK
    Posts
    39

    Talking

    Hi,

    does anyone know why this doesnt work?

    code:

    Dim DB as Database
    Dim RS as Recordset

    Set DB=OpenDatabase("c:\mydata.mdb")
    Set RS=DB.OpenRecordset("SELECT name FROM UserInfo WHERE Age>30")
    Set Text1.DataSource = rsRecordSet
    Text1.DataField = "name"

    I would be very greatful to anyone who can help!!

    Thanx
    Sajjad


  2. #2
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    736
    It appears that you are using DAO commands to create your recordset. The code I posted previously makes the connection to the fields presuming you are using ADO.

    I am not sure how to do the same using DAO.

  3. #3
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    'I suggest using sName as I think that
    'Name is a VB reserved word
    '
    'also I have named the datacontrol Data1 not Text1
    '
    'this will list the names in the recordset
    '
    'added a listbox List1 for display purposes
    '
    Private Sub Command1_Click()
        Dim DB As Database
        Dim RS As Recordset
        
        Set DB = OpenDatabase("c:\Mydata.mdb")
        Set RS = DB.OpenRecordset("SELECT sname FROM UserInfo WHERE sAge>30")
        
        While Not RS.EOF
          List1.AddItem RS!sname
          RS.MoveNext
        Wend
    
    
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  4. #4

    Thread Starter
    Member
    Join Date
    Sep 2000
    Location
    London, UK
    Posts
    39

    Arrow

    Hi,

    Is there anyway I can display the results in text boxes, and datagrids. Do I have to use ADO or DAO.

    Thank you, for all your help

    Kind Regards
    Sajjad

  5. #5
    Guest
    On the data loop I normally use
    While not (RS.EOF Or RS.BOF)
    'Do Stuff
    Wend

    If there any reason why NOT to use the BOF check as well? Does the EOF always pick up the empty resultset as well or does it depend on the data source?
    With SQL Server we normally cycle through the resultsets as well as through each resultset to get the data.

    J.

  6. #6
    Guest
    Assuming that you do not use data bound controls...

    You could show the data in a text box ...

    While Not RS.EOF
    text1.text = text1.text & ", " & RS(0)
    RS.MoveNext
    Wend

    This would give you a text box with the data all in a string seperated with commas.

    Or you could use a grid control. You can use the MS FlexGrid control but it is a bit crap. It can still be very usefull. (Code not for the Flex grid but you get the idea.)

    Grid.MaxRows = 0
    Grid.Col = 0

    While Not RS.EOF
    Grid.MaxRows = Grid.MaxRows + 1
    Grid.Row = Grid.MaxRows
    Grid.Text = RS(0)
    RS.MoveNext
    Wend

    I also find that the ListView is very useful, works kind of like this...

    Dim X as ListItem
    LV.ListItems.Clear

    While Not RS.EOF
    SET x = LV.ListItems.AddItem RS(0)
    x.SubItems(1) = RS(1)
    RS.MoveNext
    Wend

    You can also put pictures on this and it looks like explorer, where you can view it as report or icons etc..

    Hope this helps, or gives you a few ideas.

    J.

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