The Student Room Group

Vb 6 Problem, adding a record to database - error 3426

I have the following code under a command button that should add a new record to the database. When i run the program it give a 'Run time error 3426 - the action was canceled by an associated object'. My help file is missing for this error so im not sure where the coding has gone wrong.


Private Sub CmdAddApp_Click()
Dim Appointments As Recordset
Dim ClientID As Integer
Dim Stylist As String
Dim Time As String
Dim Day As String

LstClientID.Text = TxtClientIDVF.Text
TxtStylistVT.Text = TxtStylistVF.Text
TxtTimeVT.Text = TxtTimeVF.Text
TxtDayVT.Text = TxtDayVF.Text
TxtDateVT.Text = TxtDateVF.Text

ClientID = TxtClientIDVF.Text
Stylist = TxtStylistVF.Text
Time = TxtTimeVF.Text
Day = TxtDayVF.Text
Date = TxtDateVF.Text

DatAppointments.Recordset.MoveLast
DatAppointments.Recordset.AddNew
Appointments![Client ID] = ClientID
Appointments![Stylist] = Stylist
Appointments![Time] = Time
Appointments![Day] = Day
Appointments![Date] = Date

Appointments.Close
Reply 1
Hanax
I have the following code under a command button that should add a new record to the database. When i run the program it give a 'Run time error 3426 - the action was canceled by an associated object'. My help file is missing for this error so im not sure where the coding has gone wrong.



You haven't set the recordset or database to anything.

Enable ActiveX object in your components and ActiveX Objects Library 2.8( i think) in your references

Use this code:

VB6 coding for an OLEDB connection to a Microsoft access database using the ActiveX reference:


Global cnndb As New ADODB.Connection

Public Sub Connection()
Dim cnnString As String
cnnString = App.Path & "\dbname.mdb"
With cnndb
.CursorLocation = adUseClient
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0" _
& ";Data Source=" & cnnString & _
";User Id=admin;Password=;"
.Open
End With

End Sub


Then use some other code for your recordsets. If you want it, just ask. :smile:
Reply 2
Sorry just noticed i did miss the line:

Set Appointments = DatAppointments.Recordset

I did include it wen i run the code and i still get the error. Im using the 5.0 data control not the OLEDB connection
Reply 3
Acess 2003 db? If yes then PLEASE use Active X ADODB connections.
Reply 4
yeh access 2003, sorry to disappoint! thats the only way of using data controls that our teacher has shown us, the majority of our class that our using VB and access are using the 5.0 data controls. I know that i should use the other type but my project is almost done and i cant be bothered changing, it does the job.

Ive sorted the problem now, i was using the .MoveLast before i used the .AddNew and it was causing an error when i added the first record as there was no move last.

Latest

Trending

Trending