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

    DAO problem...

    I posted this in General VB, but I'll post it here too.

    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
    Hold up you referenced ADO but your using DAO code??

    I wont mention ado!! Yet anyway!

  3. #3
    PowerPoster Beacon's Avatar
    Join Date
    Jan 2001
    Location
    Pub Floor
    Posts
    3,188
    ANyways try this sunshine!

    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 usertable.[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

  4. #4

    Thread Starter
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    OOPS! I meant DAO... I hate databases, and I don't really want to learn them, but I have to if I want a decent job with VB or programming in general. I'll try that and see if it works.

    Thanks Beacon
    <removed by admin>

  5. #5

    Thread Starter
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    Thanks Beacon. That worked exactly like I wanted it to. You are da man.
    <removed by admin>

  6. #6
    PowerPoster Beacon's Avatar
    Join Date
    Jan 2001
    Location
    Pub Floor
    Posts
    3,188
    Hey whats wrong with db's? Easy to use, efficient etc etc.

    No probs joey anytime!
    Have fun!!
    later
    b

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