请参阅下文。我有一个连续表单,我在其中添加了一个命令按钮。命令按钮打开一个弹出表单。该表单包含一个子表单。我已将其设置为用户发表评论后无法编辑或删除。我遇到了一个问题,Access 会不时更新,如果您将打字中点留在聊天框中,那么它会保存记录,从而将用户锁定,因为他们没有编辑选项。我只想让他们添加记录。建立父级和子级链接。我希望客户的详细信息位于顶部,以便该人可以看到他们正在与谁交谈。我还有一个子表单,其中显示了之前访问研讨会的所有请求。
我已包含此代码以阻止其更新。
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.Dirty = True And (ChatText = Null Or Outcome = Null Or Called = False Or DateTimeCalled = Null) Then
Cancel = True
End If
End Su
b
我遇到的问题是 Access 似乎想要更新,但随后它读取了代码但没有。然后,这会突出显示文本,当您继续键入时,它会删除突出显示的文本。
任何帮助将不胜感激。还是个新手。
记录表
有人建议我使用未绑定的表单,但我作为新手正在挣扎。 VBA 伤害了我..:)
这是代码:
Private Sub CallMade_Click()
Dim err As Integer
Dim db As Database
Dim rec As Recordset
Set db = CurrentDb
'Check that all fields are filled in
txtChat.SetFocus
If txtChat.Text = "" Then
err = err + 1
MsgBox "Please fill in the Chat!" & err
End If
txtOutcome.SetFocus
If txtOutcome.Text = "" Then
err = err + 1
MsgBox "Please fill in the Outcome!"
End If
'if no errors insert data
If err < 1 Then
Set rec = db.OpenRecordset("CustChats", Options:=dbAppendOnly)
rec.AddNew
rec("Chattext") = Me.txtChat
rec("Outcome") = Me.txtOutcome
rec("DateTimeCalled") = Now()
rec("RegNo") = Me.RegNo
rec("DateofService") = Me.DateofService
rec("Called") = True
rec.Update
rec.Close
db.Close
End If
End Sub
但是我不断从 db.openrecordset 命令行收到类型不匹配错误。不知道从这里到哪里。
注意:由于用户较多(50),所以前端和后端是分开的
下面更正的代码已经解决了问题。
谢谢https://stackoverflow.com/users/12056172/shahram-alemzadeh
Private Sub CallMade_Click()
Dim err As Integer
Dim db As DAO.Database
Dim rst As DAO.Recordset
Set db = CurrentDb
'Check that all fields are filled in
txtChat.SetFocus
If txtChat.Text = "" Then
err = err + 1
MsgBox "Please fill in the Chat Box!"
End If
RegNo.SetFocus
If RegNo.Text = "" Then
err = err + 1
MsgBox "This Customer has no Reg!!!"
End If
txtOutcome.SetFocus
If txtOutcome.Text = "" Then
err = err + 1
MsgBox "Please fill in the Outcome!"
End If
'if no errors insert data
If err < 1 Then
Dim Msg, Style, Response
Msg = "Are you sure you want to Log this call?"
Style = vbYesNo + vbCritical + vbDefaultButton1
Response = MsgBox(Msg, Style)
If Response = vbYes Then ' User chose Yes.
Set rst = db.OpenRecordset("CustChats", dbOpenDynaset)
rst.AddNew
rst!ChatText = Me.txtChat
rst!Outcome = Me.txtOutcome
rst!DateTimeCalled = Now()
rst!RegNo = Me.RegNo
rst!DateofService = Me.DateofService
rst!Called = True
rst.Update
rst.MoveLast
rst.MoveFirst
rst.Close
Set rst = Nothing
Set db = Nothing
MsgBox "Call Logged!", vbInformation
Me.txtChat = ""
Me.txtOutcome = ""
Else ' User chose No.
MsgBox "You have not logged this call!"
End If
End If
End Sub