iankerry
Registered User.
- Local time
- Today, 05:58
- Joined
- Aug 10, 2005
- Messages
- 190
Hi Guys,
I am not a very experienced programmer, so please bear with my code!
I needed to write this code, because I needed to create a new record in a FILM table, and at the same time create a new record in a FILM_COPIES` using the value of the newly created FilmID to place in the field tblFilms_ID in the filmcopies database.
The routine does what i need it to do. Eventually, I would like to make this a NOTINLIST routine, but baby steps.
The problem I have is, that the routine seems to save two records for the entry i am working on in the Films table. If I use the navigation key to enter a new record, or if i close the NewFilmsForm it creates another copy.
How can I stop it saving again?
many thanks
I am not a very experienced programmer, so please bear with my code!
I needed to write this code, because I needed to create a new record in a FILM table, and at the same time create a new record in a FILM_COPIES` using the value of the newly created FilmID to place in the field tblFilms_ID in the filmcopies database.
The routine does what i need it to do. Eventually, I would like to make this a NOTINLIST routine, but baby steps.
The problem I have is, that the routine seems to save two records for the entry i am working on in the Films table. If I use the navigation key to enter a new record, or if i close the NewFilmsForm it creates another copy.
How can I stop it saving again?
many thanks
Code:
Private Sub savebutton_Click()
Dim rs As DAO.Recordset
Dim tid As Integer
Dim tdata As String
tdata = NewData
Set rs = CurrentDb.OpenRecordset("dbo_films", dbOpenDynaset, dbSeeChanges)
rs.AddNew
rs("film name") = NewData
'create data i need to save from the new film field
rs("film name") = NFN 'NFN is the name of the [film name] field
tid = rs("ID") ' save the film id for the next bit
rs.Update ' - this saves and creates the new Film record?
'DoEvents
Set rs = CurrentDb.OpenRecordset("dbo_filmcopies", dbOpenDynaset, dbSeeChanges)
rs.AddNew
rs("tblFilms_ID") = tid
rs.Update
MsgBox "New Film Saved and a Film Copy made."
rs.Close
DoCmd.GoToRecord , , acNewRec ' to clear the form for the next record
End Sub