Solved

From one form, opening another form and finding matching data

Posted on 2011-09-21
6
321 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
ID: 36572653
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
ID: 36572691
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
ID: 36572696
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:msmerry
ID: 36572745
mbizup, thanks too - I will try that tomorrow
0
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 167 total points
ID: 36573294
try this


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

Author Closing Comment

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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

680 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