Insert new record into new access 2000 table

Lyda_Faye

New Member
Joined
Feb 20, 2003
Messages
49
I am using the foilowing statements to add a new record to an access table:

Set rs3 = db.OpenRecordset("ADJ")

rs3.MoveLast
rs3.MoveNext
rs3.AddNew
rs3![CTLNO] = wCTLNO
rs3![ADJAMT] = formadj
rs3![ADJDATE] = wadjdate
rs3![GRANTNAME] = wgname
rs3![USERID] = wuserid
rs3.Update
rs3.Close

I also used this statement but got the same results:

db.Execute "Insert into ADJ (CTLNO, ADJAMT, ADJDATE, GRANTNAME, USERID) values ('" & wCTLNO & "', '" & formadj & "', '" & wadjdate & "', '" & wgname & "', '" & wuserid & "')"


Problem is that it is adding two of the same records. It is adding a new one to the end of the table like it should but it is also overwriting the first record in the table. I can't figure out why it does this. I don't want the first record overwritten, just want one new record.

I am also getting a WRITE CONFLICT error when I close the form that runs this code. I am the only one using this application. Any ideas why would really help.

Please help!
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Well I can help with some of your problems. There is no need to do the move last or next before the addnew. Access knows where the new record must go at all times. Prove it to yourself with a few Debug.Print as in this example:

Option Compare Database
Option Explicit


Public Sub fAddRec()
Dim db As Database
Dim rs3 As Recordset
Set db = CurrentDb()
Set rs3 = db.OpenRecordset("Rolls of Film")

Debug.Print "Film ID No:", rs3![FilmID]

rs3.MoveLast
Debug.Print "Film ID No:", rs3![FilmID]

'rs3.MoveNext ' This will produce a no current record error!
'Debug.Print "Film ID No:", rs3![FilmID]

rs3.AddNew
rs3![FilmTitle] = "Testing"
rs3![FilmType] = "XPS-400"
rs3![FilmSpeed] = "400"
rs3![ColorFilm] = True
rs3![FilmExpirationDate] = "02/02/2004"
rs3![DateDeveloped] = "03/04/2003"
rs3![DevelopedBy] = "RJE"
rs3![Camera] = "Olympus OM2-n"
rs3.Update
Debug.Print "The End Film ID No:", rs3![FilmID]

rs3.Close

End Sub
 
Upvote 0

Forum statistics

Threads
1,221,517
Messages
6,160,260
Members
451,635
Latest member
nithchun

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top