|
-
Dec 1st, 2006, 05:59 PM
#1
Thread Starter
Frenzied Member
[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:
.Fields("uname") = txtUser.Text
Can anyone help my whole code is below.
VB Code:
Public CN As New ADODB.Connection
Public RS As New ADODB.Recordset
Private Sub cmdClose_Click()
CN.Close
Unload Me
End Sub
Private Sub cmdDelete_Click()
With RS
CN.Execute "DELETE * FROM users WHERE uname ='" & .Fields("uname") & "'"
.Requery ' update our datagrid
End With
End Sub
Private Sub cmdNew_Click()
txtUser.Text = ""
txtPass.Text = ""
RS.AddNew
End Sub
Private Sub cmdSave_Click()
With RS
If txtUser.Text <> "" And txtPass.Text <> "" Then
.Fields("uname") = txtUser.Text
.Fields("pass") = txtPass.Text
.Update
End If
End With
End Sub
Private Sub Form_Load()
CN.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db1.mdb"
RS.CursorLocation = adUseClient
RS.Open "SELECT * FROM users ORDER BY uname ASC", CN, adOpenStatic, adLockOptimistic
Set DataGrid1.DataSource = RS
DataGrid1.Columns(0).Caption = "Username"
DataGrid1.Columns(1).Caption = "Password"
End Sub
Last edited by Jamie_Garland; Dec 1st, 2006 at 09:14 PM.
-
Dec 1st, 2006, 06:07 PM
#2
Re: Help Plz
At EOF shouldn't you be using AddNew and not Update?
-
Dec 1st, 2006, 06:08 PM
#3
Thread Starter
Frenzied Member
Re: Help Plz
Nope still get the same error
-
Dec 1st, 2006, 06:28 PM
#4
Re: Help Plz
VB Code:
Private Sub cmdSave_Click()
With RS
If RS.EOF Then
.AddNew
End If
If txtUser.Text <> "" And txtPass.Text <> "" Then
.Fields("uname") = txtUser.Text
.Fields("pass") = txtPass.Text
.Update
End If
End With
End Sub
-
Dec 1st, 2006, 06:35 PM
#5
Thread Starter
Frenzied Member
Re: Help Plz
What would i do to do a search for a username in the program?
-
Dec 1st, 2006, 06:54 PM
#6
Re: Help Plz
VB Code:
CN.Execute "Select * FROM users WHERE uname ='" & txtUser.Text & "'"
-
Dec 1st, 2006, 07:28 PM
#7
Thread Starter
Frenzied Member
Re: Help Plz
i done the following code but it dosent show the records in the textboxes when found.
VB Code:
Private Sub Command2_Click()
With RS
CN.Execute "Select * FROM users WHERE uname ='" & Text1.Text & "'"
.Fields("uname") = txtUser.Text
.Fields("pass") = txtPass.Text
.Requery
End With
End Sub
-
Dec 1st, 2006, 07:36 PM
#8
Re: Help Plz
VB Code:
Private Sub Command2_Click()
With RS
CN.Execute "Select * FROM users WHERE uname ='" & Text1.Text & "'"
[HL="#FFFF80"] txtUser.Text = .Fields("uname")
txtPass.Text = .Fields("pass")[/HL]
'.Requery ?
End With
End Sub
-
Dec 1st, 2006, 07:39 PM
#9
Thread Starter
Frenzied Member
Re: Help Plz
When i type that code in nothing happens.
VB Code:
With RS
CN.Execute "Select * FROM users WHERE uname ='" & Text1.Text & "'"
txtUser.Text = .Fields("uname")
txtPass.Text = .Fields("pass")
End W
-
Dec 1st, 2006, 07:43 PM
#10
Re: Help Plz
It works for me. Do you have a field called Text1?
-
Dec 1st, 2006, 07:45 PM
#11
Re: Help Plz
Could the case of the name be the problem? For example are you looking for "smith" when the name is "Smith"?
-
Dec 1st, 2006, 07:46 PM
#12
Thread Starter
Frenzied Member
Re: Help Plz
nope i tried both ways. Or is there a better like using an inputbox or something.
-
Dec 1st, 2006, 07:47 PM
#13
Re: Help Plz
Please zip up your project with your database and attach it.
-
Dec 1st, 2006, 07:48 PM
#14
Thread Starter
Frenzied Member
-
Dec 1st, 2006, 07:57 PM
#15
Re: Help Plz
I used "Mark" as the name and "brodie" as the password and I logged in successfully. Is there something else I should be doing?
-
Dec 1st, 2006, 07:59 PM
#16
Thread Starter
Frenzied Member
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.
-
Dec 1st, 2006, 08:02 PM
#17
Re: Help Plz
In the project you sent me there is no reference to Form1.
-
Dec 1st, 2006, 08:03 PM
#18
Thread Starter
Frenzied Member
Re: Help Plz
what do u mean no referance
-
Dec 1st, 2006, 08:07 PM
#19
Re: Help Plz
There is no "Load Form1" anyplace so the form is not shown. But I just now added that code after the login and I'll take a look at the problem you mentioned.
-
Dec 1st, 2006, 08:08 PM
#20
Thread Starter
Frenzied Member
Re: Help Plz
oh im sorry must have forgot to add it.
-
Dec 1st, 2006, 08:10 PM
#21
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:
Private Sub Command1_Click()
On Error Resume Next
With RS
If MsgBox("Update The Record?", vbQuestion + vbYesNo, "Confirm") = vbYes Then
.Fields("uname") = txtUser.Text
.Fields("pass") = txtPass.Text
.Update
.Requery
MsgBox "The current record has been updated", vbInformation, "Update Successful"
End If
End With
End Sub
-
Dec 1st, 2006, 08:11 PM
#22
Thread Starter
Frenzied Member
-
Dec 1st, 2006, 08:16 PM
#23
Re: Help Plz
Well then I'm totally confused. In posts #7 through #12 we were talking about data showing up in textboxes but it does not seem that Command1 has anything to do with that.
-
Dec 1st, 2006, 08:17 PM
#24
Thread Starter
Frenzied Member
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.
-
Dec 1st, 2006, 08:23 PM
#25
Re: Help Plz
The code in post #8 does that.
-
Dec 1st, 2006, 08:24 PM
#26
Thread Starter
Frenzied Member
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
-
Dec 1st, 2006, 08:57 PM
#27
Re: Help Plz
ADO isn't something I use very often so there may be a better way of doing this but...
VB Code:
Private Sub Command2_Click()
With RS
.Close
RS.Open "Select * FROM users WHERE uname ='" & Text1.Text & "'"
txtUser.Text = .Fields("uname")
txtPass.Text = .Fields("pass")
End With
End Sub
-
Dec 1st, 2006, 09:01 PM
#28
Thread Starter
Frenzied Member
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:
With RS
.Close
RS.Open "Select * FROM users WHERE uname ='" & Text1.Text & "'"
txtUser.Text = .Fields("uname")
txtPass.Text = .Fields("pass")
End With
Last edited by Jamie_Garland; Dec 1st, 2006 at 09:04 PM.
-
Dec 1st, 2006, 09:05 PM
#29
Re: Help Plz
Put the Requery back in.
VB Code:
Private Sub Command2_Click()
With RS
.Close
RS.Open "Select * FROM users WHERE uname ='" & Text1.Text & "'"
txtUser.Text = .Fields("uname")
txtPass.Text = .Fields("pass")
.Requery
End With
End Sub
-
Dec 1st, 2006, 09:06 PM
#30
Thread Starter
Frenzied Member
-
Dec 1st, 2006, 09:09 PM
#31
Re: {RESOLVED} Help Plz
You're welcome. Did you know that you can more easily mark the thread resolved by pulling down the Thread Tools menu and clicking the Mark Thread Resolved button?
-
Dec 1st, 2006, 09:11 PM
#32
Thread Starter
Frenzied Member
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.?
-
Dec 1st, 2006, 09:14 PM
#33
Re: {RESOLVED} Help Plz
I guess the best thing would be to have a "Refresh" button that would do a .Close and a Select *, followed by another .Requery.
-
Dec 1st, 2006, 09:41 PM
#34
Thread Starter
Frenzied Member
Re: Help Plz
How would i go about getting the refresh button to work.
-
Dec 1st, 2006, 11:32 PM
#35
Hyperactive Member
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:
Private Sub Command1_Click()
On Error Resume Next
With RS
If MsgBox("Update The Record?", vbQuestion + vbYesNo, "Confirm") = vbYes Then
' .Fields("uname") = txtUser.Text
' .Fields("pass") = txtPass.Text
.Update
.Requery
MsgBox "The current record has been updated", vbInformation, "Update Successful"
End If
End With
End Sub
-
Dec 2nd, 2006, 02:09 AM
#36
Re: Help Plz
 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:
Private Sub cmdRefresh_Click()
With RS
.Close
RS.Open "Select * FROM users"
.Requery
End With
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|