保存例程在表中创建两行...除了注释一个空白,另一个是好的?

时间:2013-01-15 17:44:00

标签: vba access-vba

我有一个userform,当用户点击按钮时,它会打开一个新的评论日志表单。在这个新表单中,我提取所有相关注释并将其显示在子表单/数据表中。

在第二种形式中,我有一个评论字段,允许输入新评论。当用户单击添加按钮时,他们可以输入文本然后单击保存按钮,注释将保存到关联的表

(我正在阻止对第二张表单进行编辑和删除...只允许添加)

一切似乎都很好而且效果很好,但是,当我去附加表时,有一条评论附加了两条记录。在两个记录中,注释文本都存在,但在第一个记录中,缺少所有其他数据元素。第二个记录是完美的。

我出错的任何想法?

Private Sub AddNew_Click()
Me.Item_ID = Forms![F_First_Form]![ID]
Me.Item_Number = Forms![F_First_Form]![Item Number]
Me.Form_Name = "F_First_Form"
Me.User_ID = (Environ$("Username"))
Me.Comment.SetFocus
End Sub

Private Sub Form_Load()

Me.Item_ID = Forms![F_First_Form]![ID]
Me.Item_Number = Forms![F_First_Form]![Item Number]
Me.Form_Name = "F_First_Form"
Me.User_ID = (Environ$("Username"))
Me.AddNew.SetFocus
End Sub
Private Sub SaveComment_Click()
 Dim dbs As DAO.Database
    Dim rst As DAO.Recordset

Set dbs = CurrentDb()
Set rst = dbs.TableDefs("Conversation_Log").OpenRecordset
If Me.Comment = vbNullString Or Me.Dirty = False Then
Exit Sub
Else
With rst
.AddNew
!Form_Name = "F_First_Form"
    !User_ID = (Environ$("Username"))
!Item_Number = Me.Item_Number
!Item_ID = Me.Item_ID
!Comment = Me.Comment
.Update
End With
Me.Requery
Me.Refresh
MsgBox "Your comment has been saved"

End If
End Sub

1 个答案:

答案 0 :(得分:0)

尝试在表单加载例程中注释掉AddNew:

Private Sub Form_Load()
    Me.Item_ID = Forms![F_First_Form]![ID]
    Me.Item_Number = Forms![F_First_Form]![Item Number]
    Me.Form_Name = "F_First_Form"
    Me.User_ID = (Environ$("Username"))
    **'Me.AddNew.SetFocus**

End Sub