我有一个为用户添加记录的表格。在用户单击表单上的按钮添加数据库之后,数据库将自动向该记录添加ID。
我也有一个用户活动日志。我想在表单添加记录时记录记录的自动生成的ID号。如何通过表单的onClick事件访问该号码?
Private Sub btnAddTax_Click()
Dim SQL As String
SQL = "INSERT INTO tblMain ( field1, field2,... )" _
& "SELECT Forms![field1Box], Forms![field2Box],...;"
DoCmd.RunSQL SQL
MsgBox "Tax Added to the Database"
DoCmd.OpenForm "frmMainScreen"
DoCmd.Close acForm, Me.Name
Dim tempString As String
tempString = "Added a record"
Logging (tempString)
End Sub
答案 0 :(得分:0)
考虑按钮单击事件中的代码:
DoCmd.RunCommand acCmdSaveRecord
Debug.Print Me!ID 'or do something else with ID