Here2Domin8
asked on
Run Time Error 91
I am trying to write a simple database program. My problem is when one of the forms loads I get a run time error 91. Here is a copy of the code from this form. Debug highlights my error at UserInfo.Recordset.AddNew. I tried removing that line of code and get the same error code, only then it points to UserInfo.Recordset.Fields( "username" ) = txtName.Text. I have a connection to the DB "UserInfo" and the field names are correct. Any help would be greatly appreciated.
-------------------------- ---------- ---------- ---------- --
Option Explicit
Private Sub cmdCancel_Click()
End
End Sub
Private Sub cmdClear_Click()
txtName.Text = ""
txtPassword.Text = ""
End Sub
Private Sub cmdConfirm_Click()
UserInfo.Recordset.Fields( "username" ) = txtName.Text
UserInfo.Recordset.Fields( "password" ) = txtPassword.Text
UserInfo.Recordset.Update
Register.Hide
Login_form.Show
End Sub
Private Sub Form_Load()
UserInfo.Recordset.AddNew
End Sub
--------------------------
Option Explicit
Private Sub cmdCancel_Click()
End
End Sub
Private Sub cmdClear_Click()
txtName.Text = ""
txtPassword.Text = ""
End Sub
Private Sub cmdConfirm_Click()
UserInfo.Recordset.Fields(
UserInfo.Recordset.Fields(
UserInfo.Recordset.Update
Register.Hide
Login_form.Show
End Sub
Private Sub Form_Load()
UserInfo.Recordset.AddNew
End Sub
You say you've connected to the DB. Have you also populated the recordset ?
ASKER
Hi bkt,
UserInfo is the ADO controller name, it is not declared anywhee in the code. This is a program I found on the web and am trying to get working so I can modify it for my own needs. Here is where I found it: <a href="http://www.vbtutor.net/lesson22.html">here</a>
I tried adding the line
Dim UserInfo As New ADODB.Connection
but then I get a compiler error saying "Member already exists in a object module from which this object module derives"
UserInfo is the ADO controller name, it is not declared anywhee in the code. This is a program I found on the web and am trying to get working so I can modify it for my own needs. Here is where I found it: <a href="http://www.vbtutor.net/lesson22.html">here</a>
I tried adding the line
Dim UserInfo As New ADODB.Connection
but then I get a compiler error saying "Member already exists in a object module from which this object module derives"
Also you may want to try moving your AddNew to the start of cmdConfirm_Click rather than having it in the Load event;
i.e.
Private Sub cmdConfirm_Click()
UserInfo.AddNew
UserInfo.Recordset.Fields( "username" ) = txtName.Text
UserInfo.Recordset.Fields( "password" ) = txtPassword.Text
UserInfo.Recordset.Update
Register.Hide
Login_form.Show
End Sub
i.e.
Private Sub cmdConfirm_Click()
UserInfo.AddNew
UserInfo.Recordset.Fields(
UserInfo.Recordset.Fields(
UserInfo.Recordset.Update
Register.Hide
Login_form.Show
End Sub
ASKER
carl,
moving AddNew allows the form to load but when I click confirm I get a compiler error saying "Method or data member not found"
moving AddNew allows the form to load but when I click confirm I get a compiler error saying "Method or data member not found"
Where is UserInfo defined.
What is it?
What is it?
Sorry, that should have been:
UserInfo.Recordset.AddNew
UserInfo.Recordset.AddNew
did you
Set UserInfo = New Adodb.recordset
??
Set UserInfo = New Adodb.recordset
??
Where did you open the recordset?
I think Mikal613 might have it with
Set UserInfo = New Adodb.recordset
Set UserInfo = New Adodb.recordset
But according to the code snippet posted by Here2Domin8, UserInfo isn't a recordset itself, its an object that contains a recordset.
ok so
Set Userinfo = CreateObject("Wahtevr")
Set Userinfo = CreateObject("Wahtevr")
According to the website that Here2Domin8 mentioned. UserInfo is an ADO control.
Here2Domin8 have you set the "recordsource" property on the ADO Control ?
Here2Domin8 have you set the "recordsource" property on the ADO Control ?
ASKER
moving UserInfo.Recordset.AddNew to cmdConfirm produces same error 91 when clicked
Set UserInfo = New Adodb.Recordset produces a run time error'438': "object does not support this property or method"
I get the same message when I attempt to adda new record to the library from the library form which I can get into from the login form with no problems now that I moved AddNew to the cmdConfirm_Click
Set UserInfo = New Adodb.Recordset produces a run time error'438': "object does not support this property or method"
I get the same message when I attempt to adda new record to the library from the library form which I can get into from the login form with no problems now that I moved AddNew to the cmdConfirm_Click
ASKER
carl,
record source is correct
command type 2
table UserInfo
record source is correct
command type 2
table UserInfo
What is UserInfo?
You need a connection object and a recordset. That's all
Public MyDb As ADODB.Connection
Dim MySet as ADODB.Recodset
set MyDb = New ADODB.Connection
set MySet = New ADODB.Recodset
You need a connection object and a recordset. That's all
Public MyDb As ADODB.Connection
Dim MySet as ADODB.Recodset
set MyDb = New ADODB.Connection
set MySet = New ADODB.Recodset
ASKER
I know the DB info is correct because I can log into the library using my username and password
ASKER
I just have the problem when I try to register a new user or try to add an entry to the library
ASKER
JR2003,
I added
Public MyDb As ADODB.Connection
Dim MySet as ADODB.Recodset
set MyDb = New ADODB.Connection
set MySet = New ADODB.Recodset
but still get same error
I added
Public MyDb As ADODB.Connection
Dim MySet as ADODB.Recodset
set MyDb = New ADODB.Connection
set MySet = New ADODB.Recodset
but still get same error
ASKER
Has every one given up on this question?
ok one last time please post ALL your code well start from scratch
The problem is that there is no recordset method or property for a recordset object!
Just remove the word "recordset" from everywhere that it occurs in that form's code. I am assuming that the problem is that the code you looked at had a recordset object named recordset and you have one named UserInfo. What you want is:
Private Sub cmdConfirm_Click()
UserInfo.AddNew
UserInfo.Fields("username" ) = txtName.Text
UserInfo.Fields("password" ) = txtPassword.Text
UserInfo.Update
Register.Hide
Login_form.Show
End Sub
Just remove the word "recordset" from everywhere that it occurs in that form's code. I am assuming that the problem is that the code you looked at had a recordset object named recordset and you have one named UserInfo. What you want is:
Private Sub cmdConfirm_Click()
UserInfo.AddNew
UserInfo.Fields("username"
UserInfo.Fields("password"
UserInfo.Update
Register.Hide
Login_form.Show
End Sub
ASKER
form name: main_menu
Option Explicit
Private Sub cmdCancel_Click()
End
End Sub
Private Sub cmdLogin_Click()
main_menu.Hide
Login_form.Show
End Sub
Private Sub cmdRegister_Click()
main_menu.Hide
Register.Show
End Sub
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- -------
form name: Register
Option Explicit
Public MyDb As ADODB.Connection
Dim MySet As ADODB.Recordset
Private Sub cmdCancel_Click()
End
End Sub
Private Sub cmdClear_Click()
txtName.Text = ""
txtPassword.Text = ""
End Sub
Private Sub cmdConfirm_Click()
Set MyDb = New ADODB.Connection
Set MySet = New ADODB.Recordset
UserInfo.Recordset.AddNew
UserInfo.Recordset.Fields( "username" ) = txtName.Text
UserInfo.Recordset.Fields( "password" ) = txtPassword.Text
UserInfo.Recordset.Update
Register.Hide
Login_form.Show
End Sub
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- -------
form name: Login_form
Option Explicit
Private Sub cmdLogin_Click()
Dim usrname As String
Dim psword As String
Dim usernam As String
Dim pssword As String
Dim Msg As String
Register.UserInfo.Refresh
usrname = txtName.Text
psword = txtPassword.Text
Do Until Register.UserInfo.Recordse t.EOF
If Register.UserInfo.Recordse t.Fields(" username") .Value = usrname And Register.UserInfo.Recordse t.Fields(" password") .Value = psword Then
Login_form.Hide
frmLibrary.Show
Exit Sub
Else
Register.UserInfo.Recordse t.MoveNext
End If
Loop
Msg = MsgBox("Invalid user name or password, try again!", vbOKCancel)
If (Msg = 1) Then
Login_form.Show
txtName.Text = ""
txtPassword = ""
txtName.SetFocus
Else
End
End If
End Sub
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- --------
form name: frmLibrary
Option Explicit
Private Sub cmdCancel_Click()
txtTitle.Text = ""
txtAuthor.Text = ""
txtPublisher.Text = ""
txtYear.Text = ""
txtCategory.Text = ""
End Sub
Private Sub cmdDelete_Click()
Confirm = MsgBox("Are you sure you want to delete this record?", vbYesNo, "Deletion Confirmation")
If Confirm = vbYes Then
adoLibrary.Recordset.Delet e
MsgBox "Record Deleted!", , "Message"
Else
MsgBox "Record Not Deleted!", , "Message"
End If
End Sub
Private Sub cmdExit_Click()
End
End Sub
Private Sub cmdNew_Click()
adoLibrary.Recordset.AddNe w
End Sub
Private Sub cmdNext_Click()
If Not adoLibrary.Recordset.EOF Then
adoLibrary.Recordset.MoveN ext
If adoLibrary.Recordset.EOF Then
adoLibrary.Recordset.MoveF irst
End If
End If
End Sub
Private Sub cmdPrevious_Click()
If Not adoLibrary.Recordset.BOF Then
adoLibrary.Recordset.MoveP revious
If adoLibrary.Recordset.BOF Then
adoLibrary.Recordset.MoveL ast
End If
End If
End Sub
Private Sub cmdSave_Click()
adoLibrary.Recordset.Field s("Title") .Value = txtTitle.Text
adoLibrary.Recordset.Field s("Author" ).Value = txtAuthor.Text
adoLibrary.Recordset.Updat e
End Sub
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- --------
That is ALL the code... I set it up exact according to the website http://www.vbtutor.net/lesson22.html
Option Explicit
Private Sub cmdCancel_Click()
End
End Sub
Private Sub cmdLogin_Click()
main_menu.Hide
Login_form.Show
End Sub
Private Sub cmdRegister_Click()
main_menu.Hide
Register.Show
End Sub
--------------------------
form name: Register
Option Explicit
Public MyDb As ADODB.Connection
Dim MySet As ADODB.Recordset
Private Sub cmdCancel_Click()
End
End Sub
Private Sub cmdClear_Click()
txtName.Text = ""
txtPassword.Text = ""
End Sub
Private Sub cmdConfirm_Click()
Set MyDb = New ADODB.Connection
Set MySet = New ADODB.Recordset
UserInfo.Recordset.AddNew
UserInfo.Recordset.Fields(
UserInfo.Recordset.Fields(
UserInfo.Recordset.Update
Register.Hide
Login_form.Show
End Sub
--------------------------
form name: Login_form
Option Explicit
Private Sub cmdLogin_Click()
Dim usrname As String
Dim psword As String
Dim usernam As String
Dim pssword As String
Dim Msg As String
Register.UserInfo.Refresh
usrname = txtName.Text
psword = txtPassword.Text
Do Until Register.UserInfo.Recordse
If Register.UserInfo.Recordse
Login_form.Hide
frmLibrary.Show
Exit Sub
Else
Register.UserInfo.Recordse
End If
Loop
Msg = MsgBox("Invalid user name or password, try again!", vbOKCancel)
If (Msg = 1) Then
Login_form.Show
txtName.Text = ""
txtPassword = ""
txtName.SetFocus
Else
End
End If
End Sub
--------------------------
form name: frmLibrary
Option Explicit
Private Sub cmdCancel_Click()
txtTitle.Text = ""
txtAuthor.Text = ""
txtPublisher.Text = ""
txtYear.Text = ""
txtCategory.Text = ""
End Sub
Private Sub cmdDelete_Click()
Confirm = MsgBox("Are you sure you want to delete this record?", vbYesNo, "Deletion Confirmation")
If Confirm = vbYes Then
adoLibrary.Recordset.Delet
MsgBox "Record Deleted!", , "Message"
Else
MsgBox "Record Not Deleted!", , "Message"
End If
End Sub
Private Sub cmdExit_Click()
End
End Sub
Private Sub cmdNew_Click()
adoLibrary.Recordset.AddNe
End Sub
Private Sub cmdNext_Click()
If Not adoLibrary.Recordset.EOF Then
adoLibrary.Recordset.MoveN
If adoLibrary.Recordset.EOF Then
adoLibrary.Recordset.MoveF
End If
End If
End Sub
Private Sub cmdPrevious_Click()
If Not adoLibrary.Recordset.BOF Then
adoLibrary.Recordset.MoveP
If adoLibrary.Recordset.BOF Then
adoLibrary.Recordset.MoveL
End If
End If
End Sub
Private Sub cmdSave_Click()
adoLibrary.Recordset.Field
adoLibrary.Recordset.Field
adoLibrary.Recordset.Updat
End Sub
--------------------------
That is ALL the code... I set it up exact according to the website http://www.vbtutor.net/lesson22.html
ASKER
Prestaul
UserInfo is the ADO control name and the DB name, not the recordset
UserInfo is the ADO control name and the DB name, not the recordset
I'm sorry about that misunderstanding. I can see that the same issue was discussed above before I posted. I would again agree with JR2003 that you would probably do best to just replace the the ADO control with ADO recordsets and connections. If you need to see how this is done then there are many tutorials and examples on the web.
If you posted the database information (type, filename, tables, fields) it only looks like two tables with only a few fields, then I'm sure that we could help with the connection string and code modification.
If you posted the database information (type, filename, tables, fields) it only looks like two tables with only a few fields, then I'm sure that we could help with the connection string and code modification.
Just as a little test, change your click event code to the following:
Private Sub cmdConfirm_Click()
UserInfo.MoveFirst
MsgBox "username: " & UserInfo.Recordset.Fields( "username" )
MsgBox "password: " & UserInfo.Recordset.Fields( "password" )
Register.Hide
Login_form.Show
End Sub
This will at least verify that your connection to the DB is ok and that you can read from the tables.
Private Sub cmdConfirm_Click()
UserInfo.MoveFirst
MsgBox "username: " & UserInfo.Recordset.Fields(
MsgBox "password: " & UserInfo.Recordset.Fields(
Register.Hide
Login_form.Show
End Sub
This will at least verify that your connection to the DB is ok and that you can read from the tables.
ASKER
access 2000 database:
home_Library.mdb
tables:
Library
fields:
Title
Author
Publisher
Year
Category
UserInfo
fields:
username
password
home_Library.mdb
tables:
Library
fields:
Title
Author
Publisher
Year
Category
UserInfo
fields:
username
password
Unless you've set them in the ADO Data control's properties window,
it looks like you haven't set the ConnectionString or the RecordSource.
See here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon98/html/vbconusingadodatacontrol.asp
it looks like you haven't set the ConnectionString or the RecordSource.
See here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon98/html/vbconusingadodatacontrol.asp
ASKER
carl,
Compiler error "Method or data member not found"
Compiler error "Method or data member not found"
ASKER
connection string:
Provider=Microsoft.Jet.OLE DB.4.0;Dat a Source="C:\Documents and Settings\ws-its\My Documents\greg's\VB\Final_ Prog_Assig n - ADO\home_Library.mdb";Pers ist Security Info=False
recordsource:
command: type 2 - adCmdTable
table: UserInfo
Provider=Microsoft.Jet.OLE
recordsource:
command: type 2 - adCmdTable
table: UserInfo
Doh !! Missed Recordset again :o)
Should have been:
Private Sub cmdConfirm_Click()
UserInfo.Recordset.MoveFir st
MsgBox "username: " & UserInfo.Recordset.Fields( "username" )
MsgBox "password: " & UserInfo.Recordset.Fields( "password" )
Register.Hide
Login_form.Show
End Sub
Should have been:
Private Sub cmdConfirm_Click()
UserInfo.Recordset.MoveFir
MsgBox "username: " & UserInfo.Recordset.Fields(
MsgBox "password: " & UserInfo.Recordset.Fields(
Register.Hide
Login_form.Show
End Sub
ASKER
carl,
Same error 91
Same error 91
ASKER
I know I can read from the table because like I said I can login to the library from the login form. Just cant add new user, or new library entry, or view and of the entries in the library, and now apparently I can't view the entries in my UserInfo table either.
Just for kicks and giggles try replacing the click event with this:
Private Sub cmdConfirm_Click()
Dim Con As New ADODB.Connection
Dim RS As New ADODB.Recordset
Con.Open "Provider=Microsoft.Jet.OL EDB.4.0;" & _
"Data Source=C:\Documents and Settings\ws-its\My Documents\greg's\VB\Final_ Prog_Assig n - ADO\home_Library.mdb;" & _
"Persist Security Info=False"
With RS
.Open "SELECT * FROM UserInfo;", Con
.AddNew
!username = txtName.Text
!password = txtPassword.Text
.Update
.Close
End With
Register.Hide
Login_form.Show
Con.Close
Set Con = Nothing
Set RS = Nothing
End Sub
I think that this is what you are going to want to do all throughout your code.
Private Sub cmdConfirm_Click()
Dim Con As New ADODB.Connection
Dim RS As New ADODB.Recordset
Con.Open "Provider=Microsoft.Jet.OL
"Data Source=C:\Documents and Settings\ws-its\My Documents\greg's\VB\Final_
"Persist Security Info=False"
With RS
.Open "SELECT * FROM UserInfo;", Con
.AddNew
!username = txtName.Text
!password = txtPassword.Text
.Update
.Close
End With
Register.Hide
Login_form.Show
Con.Close
Set Con = Nothing
Set RS = Nothing
End Sub
I think that this is what you are going to want to do all throughout your code.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Runtime error '3251':
Current Recordset does not support updating. This may be a limitation of the provider, or of the selected locktype.
highlighted >> .AddNew
Current Recordset does not support updating. This may be a limitation of the provider, or of the selected locktype.
highlighted >> .AddNew
I had a feeling that might come next :o)
The default CursorType for the ADO control is adOpenStatic. You will need to change it to adOpenDynamic.
The default CursorType for the ADO control is adOpenStatic. You will need to change it to adOpenDynamic.
Also make sure the locktype is set to adLockOptimistic
ASKER
carl,
Great, that got it.. but I am still having a problems with the library DB.. I can add new records to it but I cannot navigate the records that are there.
Great, that got it.. but I am still having a problems with the library DB.. I can add new records to it but I cannot navigate the records that are there.
go carl
Any error message ? Have you checked the settings for the ADO control ? Specifically LockType, CursorType and Mode.
There is nothing in the code that you posted that would show data for the table as you navigate. If you are not getting any errors then the code you have is probably fine but you need to add the code to display the values in the text boxes in the Form_Load event and the cmdNext and cmdPrevious click events:
Private Sub Form_Load()
UpdateFields
End Sub
Private Sub cmdNext_Click()
If Not adoLibrary.Recordset.EOF Then
adoLibrary.Recordset.MoveN ext
If adoLibrary.Recordset.EOF Then
adoLibrary.Recordset.MoveF irst
End If
End If
UpdateFields
End Sub
Private Sub cmdPrevious_Click()
If Not adoLibrary.Recordset.BOF Then
adoLibrary.Recordset.MoveP revious
If adoLibrary.Recordset.BOF Then
adoLibrary.Recordset.MoveL ast
End If
End If
UpdateFields
End Sub
Private Sub UpdateFields()
With adoLibrary.Recordset
txtTitle.Text = !Title
txtAuthor.Text = !Author
txtPublisher.Text = !Publisher
txtYear.Text = !Year
txtCategory.Text = !Category
End With
End Sub
Private Sub Form_Load()
UpdateFields
End Sub
Private Sub cmdNext_Click()
If Not adoLibrary.Recordset.EOF Then
adoLibrary.Recordset.MoveN
If adoLibrary.Recordset.EOF Then
adoLibrary.Recordset.MoveF
End If
End If
UpdateFields
End Sub
Private Sub cmdPrevious_Click()
If Not adoLibrary.Recordset.BOF Then
adoLibrary.Recordset.MoveP
If adoLibrary.Recordset.BOF Then
adoLibrary.Recordset.MoveL
End If
End If
UpdateFields
End Sub
Private Sub UpdateFields()
With adoLibrary.Recordset
txtTitle.Text = !Title
txtAuthor.Text = !Author
txtPublisher.Text = !Publisher
txtYear.Text = !Year
txtCategory.Text = !Category
End With
End Sub
ASKER
Thanks everyone for all your help. carl gets the points cuz he answered my initial question. I appreciate all the different insite into the problem though. Keep up the great work.
How is UserInfo declared?
bkt