Solved

Passing data from one form to another

Posted on 2013-11-08
10
1,206 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
  • 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 250 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
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.
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 …

786 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