Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

From one form, opening another form and finding matching data

Posted on 2011-09-21
6
320 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

808 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