我的主窗体上有一个公共函数,它在我的子窗体中创建一个新记录(位于我的主窗体上)。我试图使用是/否消息框调用公共函数。 (即:您要更新记录吗?是 - 在子表单中创建新记录。否 - 不创建新记录)。
我可以在Y / N消息框之外调用公共函数。但是,一旦我将代码放在ElseIf语句中,我就会收到“你不能去指定的记录”。我的公共函数的“DoCmd.GoToRecord,,acNewRec”部分出错。
Public Function NewEventEntry()
'this public function creates an empty new record in the subform
Me![subform_Events].SetFocus
DoCmd.GoToRecord , , acNewRec
End Function
Private Sub RunUpdateQuery_Click()
'calling the public function works fine here
'Call NewEventEntry
If DCount("*", "qry_CheckAllBadAddress") = 0 Then
MsgBox "All addresses are marked bad.", vbExclamation
ElseIf MsgBox("Do you want to update the addres?", vbYesNo + vbQuestion, "Warning") = vbYes Then
'calling the public function here doesn't work; i receive an error saying: "You can't go to the specified record." the problem is in the public function, specifically the DoCmd.GoToRecord , , acNewRec line
Call NewEventEntry
End If
End Sub
答案 0 :(得分:0)
Me![subform_Events].SetFocus
DoCmd.GoToRecord , , acNewRec
VBA应该怎么知道,你想要转到子窗体中的新记录,而不是主窗体? ;-)
试试这个:
DoCmd.GoToRecord , "subform_Events", acNewRec
我不确定这是否有效(自从我使用子表格以来很长时间)。如果没有,我会尝试使用DAO.recordset