Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

From one form, opening another form and finding matching data

Posted on 2011-09-21
6
Medium Priority
?
340 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 668 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 664 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
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 

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

[Webinar] Cloud Security

In this webinar you will learn:

-Why existing firewall and DMZ architectures are not suited for securing cloud applications
-How to make your enterprise “Cloud Ready”, and fix your aging DMZ architecture
-How to transform your enterprise and become a Cloud Enabler

Question has a verified solution.

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

Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

963 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