传递参数与“新”创建访问窗体 [英] Passing arguments to Access Forms created with 'New'

查看:109
本文介绍了传递参数与“新”创建访问窗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为细节表单,显示所选记录的详细视图。该纪录是由不同的形式被称为搜索选择。因为我希望能够打开的细节的多个实例,不同的记录的每个细节展示,我用下面的code:

I have a form called 'detail' which shows a detailed view of a selected record. The record is selected from a different form called 'search'. Because I want to be able to open multiple instances of 'detail', each showing details of a different record, I used the following code:

Public detailCollection As New Collection    

Function openDetail(patID As Integer, pName As String)
'Purpose:    Open an independent instance of form
Dim frm As Form
Debug.Print "ID: " & patID

'Open a new instance, show it, and set a caption.
Set frm = New Form_detail
frm.Visible = True
frm.Caption = pName


detailCollection.Add Item:=frm, Key:=CStr(frm.Hwnd)

Set frm = Nothing
End Function

PatID是我希望在这个新的实例,以显示记录的主键的细节。调试打印行打印出正确的PatID,所以我有它可用。我该如何将它传递到窗体的新实例?

PatID is the Primary Key of the record I wish to show in this new instance of 'detail.' The debug print line prints out the correct PatID, so i have it available. How do I pass it to this new instance of the form?

我试图设置新形式的OpenArgs,但我得到一个错误,指出OpenArgs是只读的。经过研究,OpenArgs只能由的DoCmd设置(这是行不通的,因为当时我没有得到形式的独立实例)。创建表单对象时,我可以找到关于允许的参数没有文档。很显然,微软不考虑构造是一个方法,根据文档最少。我应该如何处理呢? (PLZ别跟我将它设置为一个无形的文本框或东西)谢谢你们,你们是最好的网上的回答这些问题对我来说。我爱你们!

I tried to set the OpenArgs of the new form, but I get an error stating that OpenArgs is read only. After researching, OpenArgs can only be set by DoCmd (which won't work, because then I don't get independent instances of the form). I can find no documentation on the allowable parameters when creating a Form object. Apparently, Microsoft doesn't consider a Constructor to be a Method, at least according to the docs. How should I handle this? (plz don't tell me to set it to an invisible text box or something) Thanks guys, you guys are the best on the net at answering these questions for me. I love you all!

来源$ C ​​$ C从拍摄的多实例形式: http://allenbrowne.com/ SER-35.html

Source Code for the multi-instance form taken from: http://allenbrowne.com/ser-35.html

推荐答案

在你的Form_detail,创建一个自定义属性。

Inside your Form_detail, create a custom property.

Private mItemId As Long

Property Let ItemID(value as Long)
    mItemId = value
    ' some code to re query Me
End Property

Property Get ItemId() As Long
    ItemId = mItemId
End Property

那么,在code,创建表格,你可以做到这一点。

Then, in the code that creates the form, you can do this.

Set frm = New Form_detail

frm.ItemId = patId

frm.Visible = True
frm.Caption = pName

这将允许您的ID传递给新形式的实例,并确保它得到使它可见之前重新查询。无需每次都加载所有的结果,如果你总是用打开表单荷兰国际集团它。你让物业加载,而不是传统的的Form_Load 事件的数据。

This will allow you to pass an ID to the new form instance, and ensure it gets requeried before making it visible. No need to load all of the results every time if you're always opening the form by Newing it. You let the property load the data instead of the traditional Form_Load event.

这工作,因为Access窗体模块不外乎荣耀的类。希望这可以帮助。

This works because Access Form modules are nothing more than glorified classes. Hope this helps.

这篇关于传递参数与“新”创建访问窗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆