i need help in adding a new record to the database using adodc in vb6.. i've a command button named add in my form...

this following is an example code, modified as you needed.

Private Sub Add_Click()
    Adodc1.Refresh
    Adodc1.Recordset.AddNew
    Adodc1.Recordset.Fields("Au_Id") = Text1.Text
    Adodc1.Recordset.Fields("Author") = Text2.Text
    Adodc1.Recordset.Fields("YearBorn") = Text3.Text
    Adodc1.Recordset.Update
    MsgBox "Data Added"
End Sub
commented: Helping.. +4

Along with a button on a form you need to have a database in place and connect to that Db from vb before you could do any database related activity.

I USED THE CODE SPECIFIED BUT I GET THE FOLLOWING RUN TIME ERROR WHEN I ADD A RECORD

RUN TIME ERROR'-2147217887 (80040e21)':

multiple-step operation generated errors. Check each status value

Post the code you are using as well as the line the error occurred on.

when i click on the add button i get the run time error that i specified in post4
this is the code of my add command button.. i used adodc to connect

Private Sub ADD_Click()
Adodc1.REFRESH
Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields("NAME") = Combo1.Text
Adodc1.Recordset.Fields("NUMBER") = Text1.Text
Adodc1.Recordset.Fields("TRANS_NUMBER") = Text2.Text
Adodc1.Recordset.Fields("DATE") = Text3.Text
Adodc1.Recordset.Fields("NETWORK") = List1.Text
Adodc1.Recordset.Fields("NATURE_OF_RECHARGE") = List2.Text
Adodc1.Recordset.Fields("AMOUNT") = Text4.Text
Adodc1.Recordset.UPDATE
MsgBox "Data Added"
End Sub

The error "Multiple Step operation" can refer to incorrect data sent to your table. Make sure that if your say field "NUMBER" can only accept numbers type (Integer), the data in Text1 contains only numbers. Check this against all your fields, especially the date field. The date format must be exactly the same as to what your database is set to. If your table can only accept "yyyy/mm/dd" but the date in Text3 is "dd/mm/yyyy", the error will be raised.

it can happen if your database connection is error or you used a static path, so when you the code running in other computer this error can occurred or a data type problem like andreRet post.

what do you mean by static path could you please define clearly

Static being that you have selected a path that does not exist on another computer by making use of an actual path and not App.Path. I don't think this your problem however. Have you tried to recreate your database. Leave the old one, you have settings there that raises errors.

i got records added to the database using adodc using the following code:

rs.MoveLast
rs.AddNew
rs(0) = Combo1.Text
rs(1) = Text1.Text
rs(2) = Text2.Text
rs(3) = Text3.Text
rs(4) = List1.Text
rs(5) = List2.Text
rs(6) = Text4.Text
rs.UPDATE
MsgBox "RECORD ADDED"

thanks for ur kind posts
regards
jaai

No problem, it was a pleasure. Happy coding.:)

commented: i am very intrested in vb programming +0

also delete the adodc1.refresh on the 2nd line

Huh?

The second line reads "rs.AddNew" in his solution, two posts up.:)

Hi all,

I was looking through this thread and noticed that I am having a similar issue with saving data entry from a vb6 form to a microsoft access 2003 form.

Can anyone please help? I am getting the error "Operation is not allowed when the object is closed."

Option Explicit
Dim cn As ADODB.Connection              ' Establishing a Connection Object that provides a connection to the data
Dim rs As ADODB.Recordset

Set cn = New ADODB.Connection
    Set rs = New ADODB.Recordset

    ' Pass the connection string as the first argument to the Open method
    cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source= \\Hmstore\hmstore\Users\Esha\QST_Job_Request\QSTJOBS.mdb; Persist security info = False"

    cn.Open

    ' With recordset
    rs.MoveLast
    rs.AddNew
    rs(0) = Text3.Text
    rs(1) = Text4.Text
    rs(2) = Text7.Text
    rs(3) = Text5.Text
    rs(4) = Combo3.Text
    rs(5) = Text6.Text
    rs(6) = Text8.Text
    rs(7) = Text10.Text
    rs(8) = Text2(1).Text
    rs(9) = Combo1(1).Text
    rs(10) = Combo1(2).Text
    rs(11) = Combo1(3).Text
    rs(12) = Combo1(4).Text
    rs(13) = Combo1(5).Text
    rs(14) = Text2(0).Text
    rs(15) = Combo2(0).Text
    rs(16) = Combo2(1).Text
    rs(17) = Combo4(0).Text
    rs(18) = Combo4(1).Text
    rs(19) = Combo4(2).Text
    rs(20) = Combo2(2).Text
    rs(21) = Combo2(3).Text
    rs(22) = Text1.Text
    rs.Update

    ' Close the database.
    cn.Close
    Set cn = Nothing

' BELOW COMMENTED OUT----was not sure which was better
'    With rs
'        .MoveLast
'        .AddNew                            ' Adding new record and updating all the fields
'        .Fields("RequestorName") = Text3.Text
'        .Fields("Phone") = Text4.Text
'        .Fields("TestPurpose") = Text7.Text
'        .Fields("DateRequested") = Text5.Text
'        .Fields("Priority") = Combo3.Text
'        .Fields("DateNeeded") = Text6.Text
'        .Fields("DateCompleted") = Text8.Text
'        .Fields("CompletedBy") = Text10.Text
'        .Fields("Program") = Text2(1).Text
'        .Fields("HeadManufacturer") = Combo1(1).Text
'        .Fields("PreampVendor") = Combo1(2).Text
'        .Fields("PreampGeneration") = Combo1(3).Text
'        .Fields("Platform") = Combo1(4).Text
'        .Fields("HeadsInstalled") = Combo1(5).Text
'        .Fields("Quantity") = Text2(0).Text
'        .Fields("IniTest") = Combo2(0).Text
'        .Fields("IniTemp") = Combo2(1).Text
'        .Fields("HeadInit_A") = Combo4(0).Text
'        .Fields("HeadInit_B") = Combo4(1).Text
'        .Fields("HeadInit_C") = Combo4(2).Text
'        .Fields("ReTest") = Combo2(2).Text
'        .Fields("ReTemp") = Combo2(3).Text
'        .Fields("SpecialRequest") = Text1.Text
'        .Update
'    End With

I found the same problem before

and your below codes :

Set cn = New ADODB.Connection
    Set rs = New ADODB.Recordset
    ' Pass the connection string as the first argument to the Open method
    cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source= \\Hmstore\hmstore\Users\Esha\QST_Job_Request\QSTJOBS.mdb; Persist security info = False"
    cn.Open

replace with

Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
 ' Pass the connection string as the first argument to the Open method
   ' cn.ConnectionString = 
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source= \\Hmstore\hmstore\Users\Esha\QST_Job_Request\QSTJOBS.mdb; Persist security info = False"

Please create a new thread.

I found the same problem before

and your codes below :

Set cn = New ADODB.Connection
    Set rs = New ADODB.Recordset
    ' Pass the connection string as the first argument to the Open method
    cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source= \\Hmstore\hmstore\Users\Esha\QST_Job_Request\QSTJOBS.mdb; Persist security info = False"
    cn.Open

try to replace with

Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
 ' Pass the connection string as the first argument to the Open method
   ' cn.ConnectionString = 
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source= \\Hmstore\hmstore\Users\Esha\QST_Job_Request\QSTJOBS.mdb; Persist security info = False"

Dim DB As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim RST As New ADODB.Recordset
Dim adoConn As ADODB.Connection

Private Sub Command1_Click()
Adodc1.RecordSource = "INSERT INTO STUDATA(UserName,Password,Course, Gender,Country) Values ('" & TxtUn & "',' " & TxtPw & " ','" & Chk & "', ' " & Opt & ,'" & Combo1.Text & "')"

Adodc1.Recordset.AddNew

Adodc1.Recordset.Fields("UserName") = TxtUn
Adodc1.Recordset.Fields("Password") = TxtPw
Adodc1.Recordset.Fields("Course") = Chk

Adodc1.Recordset.Fields("Gender") = Opt

Adodc1.Recordset.Fields("Country") = Combo1.Text
Adodc1.Recordset.Update
'Next
If MsgBox(" Record is Updated... ", vbInformation + vbOKCancel, "INFO") = vbOK Then
Exit Sub
Else
TxtUn.SetFocus

End If

End Sub

Private Sub Form_Load()
DB.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & App.Path & "\dbs.accdb;Persist Security Info=False"
Adodc1.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=f:\Work\dbs.accdb;Persist Security Info=False"
Adodc1.RecordSource = "select * from STUDATA"
Adodc1.Refresh

End Sub

Public cc As Double
Public rr As Double
Public pp As Double
Public choice As String

Private Sub ac_Click()
Text1.Text = ""
cc = 0
Text1.SetFocus
End Sub

Private Sub Command1_Click()
Text1.Text = Sqr(Text1.Text)
End Sub

Private Sub div_Click()
Text1.Text = ""
pp = cc
cc = 0
choice = "/"
End Sub

Private Sub equal_Click()
Select Case choice
Case "+"
rr = pp + cc
Text1.Text = rr
Case "-"
rr = pp - cc
Text1.Text = rr
Case "*"
rr = pp * cc
Text1.Text = rr
Case "/"
rr = pp / cc
Text1.Text = rr
End Select
End Sub

Private Sub min_Click()
Text1.Text = ""
pp = cc
cc = 0
choice = "-"
End Sub

Private Sub mul_Click()
Text1.Text = ""
pp = cc
cc = 0
choice = "*"
End Sub

Private Sub plus_Click()
Text1.Text = ""
pp = cc
cc = 0
choice = "+"
End Sub

Private Sub x_Click(Index As Integer)
Text1.Text = Text1.Text & x(Index).Caption
cc = Val(Text1.Text)
End Sub

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.