Solved

Passing data from one form to another

Posted on 2013-11-08
10
1,288 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
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.

 
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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

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…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
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.

829 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