简体   繁体   English

Microsoft Access条件在子窗体中不起作用的地方

[英]Microsoft Access Where Condition doesn't works in a subform

I built a form called: "clientlist": 我建立了一个名为:“ clientlist”的表格: 在此处输入图片说明

I put a macro with where condition on click: 我把宏放在哪里条件单击:

="IDclient_logindata=" & [Maschere]![clientlist]![IDclient] =“ IDclient_logindata =”&[Maschere]![clientlist]![IDclient]

this means that when I click on an id client, access will open another form with the respective IDclient. 这意味着当我单击一个id客户端时,访问权限将使用相应的IDclient打开另一个表单。 For example if I click on IDclient 3: 例如,如果我单击IDclient 3: 在此处输入图片说明

it open another form called "client_logindata" filter to IDclient_logindata 3. Then, I built a navigational form: 它打开另一个名为“ client_logindata”的表单以过滤IDclient_logindata3。然后,我构建了一个导航表单: 在此处输入图片说明 using clientlist as subform. 使用clientlist作为子表单。 But when I click a record, any record, it open every time the client_logindata form with IDclient_logindata form = 1, why it doesn' works in a subform? 但是,当我单击一条记录(任何记录)时,每次在ID_client_logindata form = 1的client_logindata表单中打开它,为什么它不能在子表单中工作? Design View of "Navigation Form": “导航表格”的设计视图: 在此处输入图片说明

通过这种方式解决:=“ IDclient_logindata =”&[IDclient]

When using a subform, references to controls need to be relative to the main form where the subform is treated as a child control. 使用子窗体时, 对控件的引用必须相对于将子窗体视为子控件的主窗体。

Consider adjusting the conditional to the following structure. 考虑将条件调整为以下结构。 Do note this is the English version: 请注意,这是英文版本:

="IDclient_logindata=" & Forms!myMainForm!mySubform.Form!mySubformControl

Or specifically tailored to yours (be sure to get exact spelling of all objects): 或专门为您量身定做(请确保所有对象的拼写正确):

="IDclient_logindata=" & Forms!NavigationForm!clientlist.Form!IDclient

The OP has found a working solution which is much simpler than what follows. OP找到了一个可行的解决方案,它比随后的解决方案简单得多。 However, I was still interested to see if we could get something on the original model to work, and I'd guess that for users attempting to achieve the same thing using VBA rather than embedded macro's the following may still be useful. 但是,我仍然很想知道我们是否可以在原始模型上使用某些功能,并且我猜想对于尝试使用VBA而不是嵌入式宏的用户来说,以下内容可能仍然有用。


The issue with the code in the original question is that the relevant form isn't open at the 'top level' but as a subform. 原始问题中的代码存在问题,即相关表单不是在“顶层”打开,而是作为子表单打开。

Form "normal" subforms, you'd refer to the control on the subform like this: 表单“普通”子表单,您可以像下面这样引用子表单上的控件:

Forms!navform!clientlist.form!IDclient

Where navform is the name of the outer form. 其中navform是外部表单的名称。 Or in the generalised case, like this: 或在一般情况下,如下所示:

Forms!Mainform!Subform1.Form!ControlName

However, the "Navigation Form" Wizard, when dragging subforms onto the Add New tab in Layout view doesn't name the subforms nicely. 但是,将“子窗体”拖到“ 布局”视图中的“ 添加新”选项卡上时,“导航窗体”向导不能很好地命名子窗体。 So I had to code it this way: 所以我不得不这样编码:

Forms![Navigation Form]!NavigationSubform.Form!ControlName

To my surprise this code continued to work when I added further forms within the Navigation Forms tabs and had controls named the same as one in question. 令我惊讶的是,当我在“导航表单”选项卡中添加更多表单并且控件的名称与所讨论的表单相同时,此代码继续起作用。 I guess NavigationSubform automatically points to the tab with the current focus. 我猜想NavigationSubform自动指向当前焦点所在的选项卡。

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

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