Passing the value on a textbox control to a new re

2019-08-20 19:16发布

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

1条回答
一纸荒年 Trace。
2楼-- · 2019-08-20 20:02

On the Year1_AfterUpdate() even, adding:

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

Works as expected.

查看更多
登录 后发表回答