这次是访问问题。我有一个绑定到某个表的表单,我希望这个表单只允许通过单击“保存”按钮添加新条目(而不是编辑或删除)。第一个问题是在编辑文本框时更新了记录。我的解决方案有几个问题
Option Compare Database
Option Explicit
Private bSaveRecord As Boolean
Private Sub btCreateRecord_Click()
bSaveRecord = True
Me.tblUMgmtUser_UserDetailsID.Value = Me.tblUMgmtUserDetails_UserDetailsID.Value
Me.tbSetUserHashPW = "12312"
Me.cbSetInitPW = True
DoCmd.GoToRecord , , acNext
End Sub
Private Sub btResetRecord_Click()
ResetRecord
End Sub
Private Sub Form_AfterUpdate()
bSaveRecord = False
End Sub
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Not bSaveRecord Then
Cancel = True
Me.Undo
End If
End Sub
Private Sub Form_Load()
Me.Username.SetFocus
DoCmd.GoToRecord , , acNewRec
bSaveRecord = False
End Sub
Private Sub ResetRecord()
Dim cControl As Control
bSaveRecord = False
For Each cControl In Me.Controls
If cControl.Name Like "Text*" Then cControl = vbNullString
Next
Me.cbResponsible.Value = False
Me.Undo
End Sub
问题 1:我必须添加隐藏的文本框才能将值保存到我想要自动生成的记录中
问题2:每次打开表单时ID列都会增加,即使我之前没有添加记录
一般来说,我的解决方案感觉不是很健壮和优雅。非常感谢任何建议
非常感谢乔恩