Results 1 to 36 of 36

Thread: [RESOLVED] Help Plz

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Resolved [RESOLVED] Help Plz

    Can anyone help me with this minor problem please.

    I have deleted all my accounts from my database ok but when i type in a new username and password and click on save i get an error saying the following.

    Run-time error '3021':

    Either BOF or EOF is True, or the current record has been deleted Requested operation requires a current record.

    and it then highlights the following code.

    VB Code:
    1. .Fields("uname") = txtUser.Text

    Can anyone help my whole code is below.

    VB Code:
    1. Public CN As New ADODB.Connection
    2. Public RS As New ADODB.Recordset
    3.  
    4.  
    5. Private Sub cmdClose_Click()
    6. CN.Close
    7. Unload Me
    8. End Sub
    9.  
    10. Private Sub cmdDelete_Click()
    11.     With RS
    12.         CN.Execute "DELETE * FROM users WHERE uname ='" & .Fields("uname") & "'"
    13.         .Requery ' update our datagrid
    14.     End With
    15. End Sub
    16.  
    17. Private Sub cmdNew_Click()
    18.     txtUser.Text = ""
    19.     txtPass.Text = ""
    20.     RS.AddNew
    21. End Sub
    22.  
    23. Private Sub cmdSave_Click()
    24.     With RS
    25.         If txtUser.Text <> "" And txtPass.Text <> "" Then
    26.         .Fields("uname") = txtUser.Text
    27.         .Fields("pass") = txtPass.Text
    28.         .Update
    29.     End If
    30.     End With
    31. End Sub
    32.  
    33. Private Sub Form_Load()
    34.  
    35.     CN.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db1.mdb"
    36.     RS.CursorLocation = adUseClient
    37.     RS.Open "SELECT * FROM users ORDER BY uname ASC", CN, adOpenStatic, adLockOptimistic
    38.     Set DataGrid1.DataSource = RS
    39.  
    40.  
    41.  
    42.     DataGrid1.Columns(0).Caption = "Username"
    43.     DataGrid1.Columns(1).Caption = "Password"
    44.  
    45. End Sub
    Last edited by Jamie_Garland; Dec 1st, 2006 at 09:14 PM.

  2. #2

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: Help Plz

    Nope still get the same error

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Help Plz

    VB Code:
    1. Private Sub cmdSave_Click()
    2.     With RS
    3.         If RS.EOF Then
    4.             .AddNew
    5.         End If
    6.         If txtUser.Text <> "" And txtPass.Text <> "" Then
    7.         .Fields("uname") = txtUser.Text
    8.         .Fields("pass") = txtPass.Text
    9.         .Update
    10.     End If
    11.     End With
    12. End Sub

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: Help Plz

    What would i do to do a search for a username in the program?

  6. #6

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: Help Plz

    i done the following code but it dosent show the records in the textboxes when found.

    VB Code:
    1. Private Sub Command2_Click()
    2. With RS
    3. CN.Execute "Select * FROM users WHERE uname ='" & Text1.Text & "'"
    4.         .Fields("uname") = txtUser.Text
    5.         .Fields("pass") = txtPass.Text
    6.         .Requery
    7.        
    8.     End With
    9. End Sub

  8. #8
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Help Plz

    VB Code:
    1. Private Sub Command2_Click()
    2. With RS
    3. CN.Execute "Select * FROM users WHERE uname ='" & Text1.Text & "'"
    4. [HL="#FFFF80"]        txtUser.Text = .Fields("uname")
    5.         txtPass.Text = .Fields("pass")[/HL]
    6.         '.Requery ?
    7.        
    8.     End With
    9. End Sub

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: Help Plz

    When i type that code in nothing happens.

    VB Code:
    1. With RS
    2. CN.Execute "Select * FROM users WHERE uname ='" & Text1.Text & "'"
    3.         txtUser.Text = .Fields("uname")
    4.         txtPass.Text = .Fields("pass")
    5. End W

  10. #10

  11. #11

  12. #12

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: Help Plz

    nope i tried both ways. Or is there a better like using an inputbox or something.

  13. #13

  14. #14

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: Help Plz

    program attached.

  15. #15

  16. #16

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: Help Plz

    click on the command1 command button it should being up another form i want to have a search feature on that form so people can search the users and also look at the data grid.

  17. #17

  18. #18

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: Help Plz

    what do u mean no referance

  19. #19

  20. #20

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: Help Plz

    oh im sorry must have forgot to add it.

  21. #21
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Help Plz

    Do I have the correct and or up to date project. In the one you sent me Command1 has a cation of "Update" and the following code.


    VB Code:
    1. Private Sub Command1_Click()
    2. On Error Resume Next
    3. With RS
    4.     If MsgBox("Update The Record?", vbQuestion + vbYesNo, "Confirm") = vbYes Then
    5.     .Fields("uname") = txtUser.Text
    6.     .Fields("pass") = txtPass.Text
    7.     .Update
    8.     .Requery
    9. MsgBox "The current record has been updated", vbInformation, "Update Successful"
    10. End If
    11. End With
    12. End Sub

  22. #22

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: Help Plz

    yes thats correct

  23. #23

  24. #24

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: Help Plz

    its ment to have a search feature on Form1 but it dosent seem to be one on it can you help me add it please.

  25. #25

  26. #26

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: Help Plz

    This code dosent work

    Private Sub Command2_Click()
    With RS
    CN.Execute "Select * FROM users WHERE uname ='" & Text1.Text & "'"
    txtUser.Text = .Fields("uname")
    txtPass.Text = .Fields("pass")
    '.Requery ?

    End With
    End Sub

  27. #27
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Help Plz

    ADO isn't something I use very often so there may be a better way of doing this but...


    VB Code:
    1. Private Sub Command2_Click()
    2. With RS
    3.     .Close
    4.    
    5.     RS.Open "Select * FROM users WHERE uname ='" & Text1.Text & "'"
    6.    
    7.     txtUser.Text = .Fields("uname")
    8.     txtPass.Text = .Fields("pass")
    9. End With
    10.  
    11. End Sub

  28. #28

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: Help Plz

    Code works now but how do i get it to show the record in the DataGrid aswell. As it removes them from the datagrid and just shows up blank with the record showing in the text boxes.

    VB Code:
    1. With RS
    2.     .Close
    3.    
    4.     RS.Open "Select * FROM users WHERE uname ='" & Text1.Text & "'"
    5.    
    6.     txtUser.Text = .Fields("uname")
    7.     txtPass.Text = .Fields("pass")
    8. End With
    Last edited by Jamie_Garland; Dec 1st, 2006 at 09:04 PM.

  29. #29
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Help Plz

    Put the Requery back in.

    VB Code:
    1. Private Sub Command2_Click()
    2. With RS
    3.     .Close
    4.    
    5.     RS.Open "Select * FROM users WHERE uname ='" & Text1.Text & "'"
    6.    
    7.     txtUser.Text = .Fields("uname")
    8.     txtPass.Text = .Fields("pass")
    9.     .Requery
    10. End With
    11.  
    12. End Sub

  30. #30

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: Help Plz

    Thank you very much.

  31. #31

  32. #32

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: {RESOLVED} Help Plz

    No i didnt know that lol can i ask yopu one more question. See once the search has been done how do i get it to go back and show all the other records again. Using a timer or something like that.?

  33. #33

  34. #34

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: Help Plz

    How would i go about getting the refresh button to work.

  35. #35
    Hyperactive Member Chathura's Avatar
    Join Date
    Nov 2005
    Location
    Sri Lanka
    Posts
    345

    Re: Help Plz

    As I read your program, I didn't see any need of text boxes. You can just type on the grid cells to add a new record. The reason is you have bound the recordset to the data grid.
    You only have to do these steps
    1. Press "new" button
    2. Type your new values on Data Grid
    3. Press Update button
    VB Code:
    1. Private Sub Command1_Click()
    2. On Error Resume Next
    3. With RS
    4.     If MsgBox("Update The Record?", vbQuestion + vbYesNo, "Confirm") = vbYes Then
    5. '    .Fields("uname") = txtUser.Text
    6. '    .Fields("pass") = txtPass.Text
    7.     .Update
    8.     .Requery
    9. MsgBox "The current record has been updated", vbInformation, "Update Successful"
    10. End If
    11. End With
    12. End Sub

  36. #36
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Help Plz

    Quote Originally Posted by Jamie_Garland
    How would i go about getting the refresh button to work.
    Well, just what I said in post #33...

    VB Code:
    1. Private Sub cmdRefresh_Click()
    2. With RS
    3.     .Close
    4.    
    5.     RS.Open "Select * FROM users"
    6.    
    7.     .Requery
    8. End With
    9.  
    10. End Sub

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