WKI
WKI

Reputation: 215

Passing the value on a textbox control to a new record using the same form

I have a form which comprise of a texbox bound to a field called Year1. I want to create a new record using the new record controls in the bottom of the form and have the value on the previous record carried forward to the new record. I tried the following codes but no luck. Any help is greatly appreciated. Below is my first approach:

Private Sub Form_Current()

Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("SELECT * FROM tblMyTable")
rs.AddNew
rs.Fields("Year1").Value = Year1.Value

rs.Close

End Sub

I have also tried the following approach but no luck:

Private Sub Form_Current()
Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("SELECT * FROM tblMyTable")
     rs.Edit
     rs!Year1 = Year1.Value
     rs.Update
  rs.Close
  End Sub

Upvotes: 0

Views: 515

Answers (1)

WKI
WKI

Reputation: 215

On the Year1_AfterUpdate() even, adding:

Me.Year1.DefaultValue = "'" & Me.Year1 & "'"

Works as expected.

Upvotes: 1

Related Questions