?
Solved

Passing data from one form to another

Posted on 2013-11-08
10
Medium Priority
?
1,799 Views
Last Modified: 2013-11-09
Dear Experts

I'm using Access 2007 & need to pass data from Form A to Form B (a pop up form).

Form A contains a field [ID] which is an auto generated number

I want to open Form B in "Add mode" and pass the number from Form A [ID] to Form B [Member ID] (which is a number field)

Can anybody help? - I've tried using TempVars & open arguments but am getting nowhere
0
Comment
Question by:correlate
[X]
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
  • 5
  • 4
10 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 39634087
Try this in the code to open form B

DoCmd.OpenForm "Form B",,,,acFormAdd

Open in new window



ANd in Form B's Open Event:

Me.ID = Forms!FormA.ID

Open in new window

0
 
LVL 61

Accepted Solution

by:
mbizup earned 1000 total points
ID: 39634097
Or to pass OpenArgs

DoCmd.OpenForm "Form B", DataMode := acFormAdd, OpenArgs = Me.ID, WindowMode = acDialog

Open in new window



And use the OpenArgs anywhere in FormB's code as follows:

Something = Me.OpenArgs

Open in new window

0
 

Author Comment

by:correlate
ID: 39634161
Hi mbizup

Thanks for these - I tried the first version, but unfortunately Form A is a continuous form, so I think that's why it didn't really like it.  I have tried to pass OpenArgs but I am getting an error stating "You cannot assign a value to this object", the error highlights on Form B's code (which is below)
Private Sub Form_Open(Cancel As Integer)
Me.MemberID = Me.OpenArgs
End Sub

Open in new window

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!

 
LVL 61

Expert Comment

by:mbizup
ID: 39634169
IF the MemberID is the primary key (autonumber, for example) in FormB's recordsource, or if the control source of MemberID is somthing like "= Some value", it is a read-only field.

What are you trying to accomplish (big picture)?
0
 

Author Comment

by:correlate
ID: 39634269
The ID in Form A is an auto number, in form B it isn't.

The  bigger picture on this one is this:

Form A's data comes from the main table in the database which holds a load of contact data for a membership database. Form B has a different data source which is a table containing all the responses to events.  I have managed to get the events table updated by having a sub form inside in each member's record.  But for ease of use when I'm collecting responses to an event I wanted all members listed so I could quickly go through and update their response without having to open each individual members record to update the event table
0
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 1000 total points
ID: 39634292
using the OpenArgs for passing the info to formB,
use the load event of FormB

private sub form_load()
if me.newrecord then
   if me.openargs & ""<>"" then
       me.NameOfControlfortheID=Me.openargs
   end if
end if

end sub

change "NameOfControlfortheID" with the actual name of the control


.
0
 

Author Comment

by:correlate
ID: 39634313
Thanks, am away from my PC or a bit, but will give it a go as soon as I'm back
0
 
LVL 61

Expert Comment

by:mbizup
ID: 39634418
I'm picturing your table structure as this:

FormA's table:
     ID    --- ID/autonumber for a contact
     Various fields  -- other contact info

FormB's table:
     ID --- ID/Autonumber for an event
     ContactID  -- Numeric field, holding ID from the Form A's table (a foreign key)
     Various fields -- other event info

It sounds like you might be getting the fields on form B mixed up.   Are you trying to pass a ContactID from formA to formB?  Check your field names again, and ensure that you are you are writing the contact ID from formA to the correct field in form b.

The code in form b might be something like:

Me.ContactID = Me.OpenArgs

or this:

Me.ContactID = Forms!FormA.ID

<<  but unfortunately Form A is a continuous form >>

And this shouldn't make a difference.  If you have a record selected on your continuous form when you open formB, the ID passed to form B will be that of the currently selected record on continuous FormA.
0
 

Author Comment

by:correlate
ID: 39634444
Thanks for that - think you got the structure spot on, I will double check the field names, alas won't be able to do that tonight, but will first thing tomorrow.
0
 

Author Closing Comment

by:correlate
ID: 39635372
Thank you very much for your help - all sorted
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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Suggested Courses

765 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