简体   繁体   中英

Microsoft Access Where Condition doesn't works in a subform

I built a form called: "clientlist": 在此处输入图片说明

I put a macro with where condition on click:

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

this means that when I click on an id client, access will open another form with the respective IDclient. For example if I click on IDclient 3: 在此处输入图片说明

it open another form called "client_logindata" filter to IDclient_logindata 3. Then, I built a navigational form: 在此处输入图片说明 using clientlist as subform. 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? 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. 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.


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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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