Solved

From one form, opening another form and finding matching data

Posted on 2011-09-21
6
313 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 

Author Comment

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

Assisted Solution

by:Rey Obrero
Rey Obrero 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

932 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

10 Experts available now in Live!

Get 1:1 Help Now