Results 1 to 6 of 6

Thread: DAO problem...

  1. #1

    Thread Starter
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125

    Unhappy DAO problem...

    I am having problems with DAO. I have this same code in a different project, and it works fine, but I am trying to use the same code in a different program to open a table and get info out of it.
    OK this code works fine, to get an item out of the table:
    VB Code:
    1. Set db = OpenDatabase("C:\Windows\Desktop\inventory.mdb")
    2. strSQL = "SELECT * FROM Current WHERE ID = " & txtID.Text
    3. Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
    4. If rs.RecordCount > 0 Then
    5.     'Text1.Text = rs!ItemNo & "" 'substitute real field names
    6.     buff = rs!Price '& ""
    7.     lstReceipt.AddItem buff
    8.     txtID.Text = ""
    9. Else
    10.     MsgBox "No Match found for that ID.", vbCritical
    11. End If
    12. rs.Close
    13. db.Close

    But then I use this code to get info out of a different database and table:
    VB Code:
    1. Private Sub cmdLogin_Click()
    2. Uname = txtUsername.Text
    3. Pword = txtPassword.Text
    4. Set db = OpenDatabase("C:\Windows\Desktop\users.mdb")
    5. MsgBox "got here"
    6. strSQL = "SELECT * FROM usertable WHERE Username = " & Uname
    7. Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
    8. If rs.RecordCount = 0 Then MsgBox "No user by the name " & Uname & ". Please check the name you entered.", vbInformation: Exit Sub
    9. TestPass = rs!Password
    10. If TestPass = Pword Then MsgBox "Correct password!"
    11. rs.Close
    12. db.Close
    13. End Sub

    and I get an error with the dbOpenDynaset variable. It says somthing about Too few parameters, expected 1. So I change dbOpenDynaset to a 1, and it gets an error opening the table. This is frustrating! Just incase you are wondering, I HAVE added a reference to the ADO library, just like in the other project, and I have declared all my variables... I just don't want to post all the code.

    Please don't mention ADO, cause I have had so many f**king problem with ADO, it's not even funny.

    Thanks in advance
    -Joey
    <removed by admin>

  2. #2
    PowerPoster Beacon's Avatar
    Join Date
    Jan 2001
    Location
    Pub Floor
    Posts
    3,188
    Check db forums joey!!

  3. #3
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    Code:
    Private Sub cmdLogin_Click()
        Uname = txtUsername.Text
        Pword = txtPassword.Text
        
        Set db = OpenDatabase("C:\Windows\Desktop\users.mdb")
        Debug.Print "got here"
        
        strSQL = "SELECT * FROM usertable WHERE Username = ' " & Uname & " ' " '###
        Debug.Print strSQL
        
        Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
            
        If (rs.RecordCount = 0) Then MsgBox "No user by the name " & _
        Uname & ". Please check the name you entered.", vbInformation: Exit Sub
        
        If (rs!Password = Pword) Then MsgBox "Correct password!"
        
        rs.Close
        db.Close
    End Sub
    • Remove the spaces between the quotes (I did the above to show you
      what this was meant to be, put this as :
      Code:
      ='" & Uname & "'"
    • I HAVE added a reference to the ADO library
      Shouldn't this be DAO library? What version of Access is the database and what version of the DAO library are you using ?

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  4. #4
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Well ...

    The error you have quoted means you have got either the table name(s) or the field name(s) misspelt. Check that the table name is usertable and the field name is username. Case doesn't matter.

    It's my hunch that the table is not usertable. And once you have corrected that problem you will run into another problem, for which Alex has already given the solution.

    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  5. #5

    Thread Starter
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    Thanks guys. The table names I was using were correct honeybee. Beacon answered my question when I posted it in the DB forums, but I thank you for trying to help.

    <removed by admin>

  6. #6
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Well ...

    Damn!! That's the first time my guess went wrong!!

    I wonder if Username is a reserved word in Access like Date etc. If so, my guess is still correct.

    And I read Beacon's reply in DB Forums, and that's what prompts me to think what I am thinking.

    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

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