Solved

From one form, opening another form and finding matching data

Posted on 2011-09-21
6
311 Views
Last Modified: 2012-05-12
I have a form and subform.  The subform has a button to open another form and find the record with matching id.  The macro behind it is "1AWorksAddressfrm, Form, , [worksID]=[Forms]![1acontactsubfrm].
If I click this button on the subform I get a dialog box - Enter new parameter - [worksID]=[Forms]![1acontactsubfrm].  I then have to type the worksid in, at which point it opens correctly.

However, If I open the subform independently,  the button works perfectly and goes straight to the matching record - no dialog box, no typing.

Why? What do I need to do to make it work in the subform mode, as that is where it is needed?
0
Comment
Question by:msmerry
6 Comments
 
LVL 9

Accepted Solution

by:
borki earned 167 total points
Comment Utility
When you press the button on the subform, you want the new form to open with a value that is obtained from the subform.

When you invoke the subform as a main form the code works, because your reference is

ID = Forms!formname

However, when the subform is part of another form, eg a true subform the syntax needs to be
ID = Forms!mainform.subform

I usually avoid macros and use VBA routines instead, so I am not certain on the syntax to use in a macro.

Hope that helps


0
 
LVL 61

Assisted Solution

by:mbizup
mbizup earned 166 total points
Comment Utility
It looks like your macro is simply pointing to the subform.  You need to point to the field on the subform that contains the value for the ID:

<<  [worksID]=[Forms]![1acontactsubfrm] >>

Should be something like this (you need to substitute the correct fieldname):

 
[worksID]=[Forms]![MainForm]![1acontactsubfrm]![YourSubFormsWorkIDField]

Open in new window

However, like borki, I would use VBA instead of a Macro.  It is easier all around.  Just go into the button's property sheet, click the ... next to On Click, and select Event Procedure.

The code to put between the sub and end sub statements to open the new form would simply be:

Docmd.OpenForm "1AWorksAddressfrm",,, "[worksID]= " & Me.[YourSubFormsWorkIDField]

Open in new window

(again, substitute the correct field name for "YourSubFormsWorkIDField")
0
 

Author Comment

by:msmerry
Comment Utility
Thanks for your prompt reply.
I know that it's supposed to be much better to use VBA, but it's a foreign language to me, so I stick with what I know, and one day I'll learn VBA
I will try your suggestion tomorrow
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:msmerry
Comment Utility
mbizup, thanks too - I will try that tomorrow
0
 
LVL 119

Assisted Solution

by:Rey Obrero
Rey Obrero earned 167 total points
Comment Utility
try this


[worksID]=[Forms]![NameOfMainForm]![1acontactsubfrm].Form![YourSubFormsWorkIDField]
0
 

Author Closing Comment

by:msmerry
Comment Utility
Thanks to all of you - my knowledge grows every time I come here for help
0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now