Solved

Passing data from one form to another

Posted on 2013-11-08
10
1,067 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 119

Assisted Solution

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

746 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

16 Experts available now in Live!

Get 1:1 Help Now