vba 如何打开一个表单以从点击事件中进行编辑?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11061449/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 16:30:49  来源:igfitidea点击:

How to open a form in access to edit from on click event?

ms-accessvbavbscript

提问by Gopipuli

I got a main form which contains two coloumns which list a no/product. I had given vba code for product field click event to open preduct detail form with the selected product and it details to edit. I given code as below

我得到了一个主表单,其中包含两个列出 no/product 的列。我已经为产品字段单击事件提供了 vba 代码,以打开带有所选产品的产品详细信息表单,并对其进行编辑。我给出的代码如下

Dim stDocName As String
    Dim stLinkCriteria As String
    stLinkCriteria = Me.Product

    stDocName = "ProductDetail"
    DoCmd.openform stDocName, , , "Product = " & stLinkCriteria

When I click the product its showing a input box and while enter the value its opening the product details with correct information.

当我单击产品时,它会显示一个输入框,并在输入值时打开带有正确信息的产品详细信息。

I dont want to input the product name every time. I want this to work directly while clicking the product and should open it product details.

我不想每次都输入产品名称。我希望在单击产品时直接使用它,并且应该打开它的产品详细信息。

Please let me know how can do this ?

请让我知道怎么做?

回答by HansUp

If the [Product] field is text data type, enclose stLinkCriteriawith quotes in your OpenFormstatement.

如果 [Product] 字段是文本数据类型,请stLinkCriteriaOpenForm语句中用引号引起来。

DoCmd.OpenForm stDocName, , , "Product = '" & stLinkCriteria & "'"

回答by Gopipuli

This code help me to fix the above problem

此代码帮助我解决上述问题

Forms!Frm.SetFocus 

Const FORMNAME = "frm1"


Dim ctrl As Control
Dim strCriteria As String

On Error GoTo Err_Handler

Set ctrl = Me.ActiveControl

strCriteria = "[Product] = """ & ctrl & """"


DoCmd.OpenForm FORMNAME, WhereCondition:=strCriteria

Exit_Here:
Exit Sub

Err_Handler:
MsgBox Err.Description, vbExclamation, "Error"
Resume Exit_Here