简体   繁体   English

如果记录不存在,使用 MsgBox 打开表格到新记录或从连续表格中删除记录

[英]Use MsgBox to open form to new record or delete record from continuous form if the record does not already exist

I have a form with a continuous subform that is used to "check out" items.我有一个带有连续子表单的表单,用于“签出”项目。 If an item is entered that is not currently in the items table, an error fires.如果输入的items当前不在items表中,则会触发错误。

I would like to create a custom msgbox that will allow the user to select the next action;我想创建一个允许用户选择下一个操作的自定义msgbox either open a form to enter the new item (along with a number of details about the item) or to delete the row.打开一个表单以输入新项目(以及有关该项目的许多详细信息)或删除该行。

I have been able to fire the msgbox code and successfully open the form to enter a new item, but I cannot get the row to delete from the subform OR use SetProperty to return the value to null .我已经能够触发msgbox代码并成功打开表单以输入新项目,但我无法从子表单中删除要删除的行或使用SetProperty将值返回到null

Here is the current code to launch the MsgBox which is triggered BeforeUpdate, OnError from the control in question.这是启动MsgBox的当前代码,该代码由相关控件触发 BeforeUpdate、OnError。

Function MsgBox_NewAsset()

    MsgBoxResult = MsgBox("The Asset Number you entered is not in the system. Would you like to enter this as a new asset?", 4 + vbQuestion, "New Asset?")

    If MsgBoxResult = 6 Then
    DoCmd.SetWarnings False
    DoCmd.OpenForm "Asset Details", , , "AssetID=0"
    DoCmd.SetWarnings True

    Else
    DoCmd.SetProperty("AssetID",acPropertyValue,"")
    End If

End Function

When setting the SetProperty command using:使用以下命令设置SetProperty命令时:

DoCmd.SetProperty("AssetID",acPropertyValue,"")

I get a compile error:我收到一个编译错误:

Expected: =预期:=

I'm relatively new to VBA, so not entirely sure what this indicates.我对 VBA 比较陌生,所以不完全确定这意味着什么。

Try DoCmd.RunCommand acCmdUndo rather than DoCmd.SetProperty(...)尝试DoCmd.RunCommand acCmdUndo而不是DoCmd.SetProperty(...)

The form is sitting on an uncommitted, new record that can't be committed.表单位于无法提交的未提交的新记录上。 To roll it back, use Undo.要回滚它,请使用撤消。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM