Results 1 to 12 of 12

Thread: recordset

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2001
    Posts
    302

    recordset

    Can anyone tell me why my code doesn't work...
    Set rs2 = db.OpenRecordset("SELECT * FROM tblLicenses WHERE tblLicenses.userID=userName", dbOpenDynaset)

    username is a string defined previously ("Brian").



    thanks

  2. #2
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,539

    Re: recordset

    Originally posted by 2000a
    Can anyone tell me why my code doesn't work...
    Set rs2 = db.OpenRecordset("SELECT * FROM tblLicenses WHERE tblLicenses.userID=userName", dbOpenDynaset)

    username is a string defined previously ("Brian").



    thanks
    try Set rs2 = db.OpenRecordset("SELECT * FROM tblLicenses WHERE tblLicenses.userID='" & userName & ''", dbOpenDynaset)

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2001
    Posts
    302
    it returns 1... I have 6 records with that username...

    Set rs2 = db.OpenRecordset("SELECT * FROM tblLicenses WHERE tblLicenses.userID='" & userName & "'", dbOpenDynaset)

  4. #4
    Frenzied Member vbgladiator's Avatar
    Join Date
    May 2001
    Posts
    1,950
    What's userid in your database? an autonumber?

  5. #5
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,539
    Originally posted by 2000a
    it returns 1... I have 6 records with that username...

    Set rs2 = db.OpenRecordset("SELECT * FROM tblLicenses WHERE tblLicenses.userID='" & userName & "'", dbOpenDynaset)
    did you forget to loop through the record?


    [Highlight=VB]
    do until rs2.eof
    msgbox rs2("Username")

    loop
    [/vbvode]

  6. #6
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,539
    Originally posted by 2000a
    it returns 1... I have 6 records with that username...

    Set rs2 = db.OpenRecordset("SELECT * FROM tblLicenses WHERE tblLicenses.userID='" & userName & "'", dbOpenDynaset)
    did you forget to loop through the record?


    VB Code:
    1. do until rs2.eof
    2.      msgbox rs2("userID")
    3.  
    4.   loop

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2001
    Posts
    302
    sorry,

    the rs2 is working, but: rs2.RecordCount is only returning one record...

    I printed the userNames with a do while and they all show...
    How can I count without a loop?


    thanks

  8. #8
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,539
    Originally posted by 2000a
    sorry,

    the rs2 is working, but: rs2.RecordCount is only returning one record...

    I printed the userNames with a do while and they all show...
    How can I count without a loop?


    thanks
    .recordcount is not accurate if your using
    dbOpenDynaset
    you have to use OpenStatic or the other ones ( i forgot which one)
    but i wouldnt recommend using .recordcount cus it still loops through the records..

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2001
    Posts
    302
    Now i'm having trouble with:

    Set rs2 = db.OpenRecordset("SELECT * FROM tblLicenses WHERE tblLicenses.userID='" & userName & "' AND tblLicenses.appName='" & appName & "'", dbOpenDynaset)


    What's wrong with the AND?

    thanks

  10. #10

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2001
    Posts
    302
    too few parameters. expected 1

  12. #12
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,539
    VB Code:
    1. Dim SQL as string
    2. SQL = "SELECT * FROM tblLicenses WHERE tblLicenses.userID='" & userName & "' AND tblLicenses.appName='" & appName & "'"
    3. msgbox SQL
    4.  
    5. Set rs2 = db.OpenRecordsetdb(SQL, OpenDynaset)

    see what that prints out first

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