Solved

Passing data from one form to another

Posted on 2013-11-08
10
1,130 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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
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 developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

914 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

18 Experts available now in Live!

Get 1:1 Help Now