Reputation: 33
I want to insert some information into a database in VB6, but I get runtime error '91'. My code:
Private sub btn_click()
Fname = txtFname.text
Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields("Fname") = Fname
Adodc1.Recordset.Update
End sub
The debuger shows error on: Adodc.Recordset.AddNew
Upvotes: 0
Views: 1364
Reputation: 64
By the way you posted the code, I believe that you will populate a Recordset to insert into the database. Try as follows:
sub btn_click()
dim Adodc1 as adodb.recordset
set Adodc1 = new adodb.recordset
Fname = txtFname.text
Rs.Fields.Append "Fname", adVarChar, 20 'adVarChar = text, followed by the amount of characters
Adodc1.open()
Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields("Fname") = Fname
Adodc1.Recordset.Update
End sub
Upvotes: 0
Reputation: 5477
Runtime error '91' is Object variable or With block variable not set, which is a slightly confusing way to say that your variable contains Nothing
.
You either forgot to initialise the Adodc1
properly, or, and this is more likely, you need to initialise Adodc1.RecordSet
to something useful (like a Set Adodc1.RecordSet = New RecordSet
or related) before you can use it.
Upvotes: 1
Reputation: 406
You haven't posted the rest of the code as to where the Adhoc1 variable is created etc...
This post suggests that the RecordSet has not been initialized prior to working with it, but it's hard to be more specific without the code.
Upvotes: 1