p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Access (http://p2p.wrox.com/forumdisplay.php?f=18)
-   -   Passing data between forms (http://p2p.wrox.com/showthread.php?t=29755)

pactite May 25th, 2005 12:05 PM

Passing data between forms
I have two tables in MS Access DB with corresponding forms. In Form A, I have a text box (TextfieldA)and in Form B, I have another textbox (Textfield B). I have the database setup so that the end-users have to enter information in Form A and then, they have to enter the same information in Form B. I know how to set it up so that the end-user can select the data that they entered in Form A using a pull-down menu utilizing a query but is there a way to do this more efficiently using codes or Macros? If so how?

Any help would be greatly appreciated.

pactite May 27th, 2005 08:58 AM

Additional information:
Only TextField B in Form B share same information as Textfield A in Form A.

rjweers May 28th, 2005 09:10 AM

It's a little unclear what you want. I'll focus on the description about users entering data, though you could be asking about a more efficient way to allow entry in TextfieldA.

When you say the users have to enter the same information in Form B, does that mean you want to make them double-type the information to be sure they entered the correct information? Or are you trying to build a user friendly application where after they enter information in form A it automatically populates to form B?

In either case, you're looking at using either the BeforeUpdate event on textfieldB (if you want to make sure they entered the same value and error if not) or AfterUpdate event on textfieldA (if you want to auto-populate formB).

What you need to know is how to reference the field of the other form. This is done using the Forms collection, as follows:


E.g. Forms("FormB").TextfieldB to for the AfterUpdate event situation.

One thing that you'll probably want to do is be sure that the other form is open. This can be done by checking

If CurrentProject.AllForms("formname").IsLoaded Then

Not that it's my business, but why do you have two forms that display the same information opened at the same time? If they are so related, why not make one of them the master form and the other a subform?

Randall J Weers
Membership Vice President
Pacific NorthWest Access Developers Group

pactite May 30th, 2005 12:44 PM

Mr. Weers;

Sorry for the poor discription about my problem but your second guess about auto-populating Textfield B is correct. TextField B is the only field with same value. The rest of the information on the Form B is different. Your guess about trying to build a friendlier database is also correct. I am creating this DB as a side project at my work and the users are going to be people who never used a computer before so even though, the information is duplicative, I thought it would be easier for the ens-user to perform a simple query if all the information is in the same table.

Thank you for your assistance and can I ask for little more. Can you tell me how your codes would work and do I need to add more info.

rjweers May 31st, 2005 07:03 AM

I think this is one where you're going to have to hack through mostly on your own. But here's a little code that will do what you asked.

For the TextfieldA_AfterUpdate event, write something to the effect of:

' make sure the form is open
If CurrentProject.AllForms("formname").IsLoaded Then
    ' make sure we should populate the text field
    If isnull(Forms("formname").TextfieldB) then
        Forms("formname").TextfieldB = Me.TextfieldA
    End If
End If

The trouble is, there probably is a lot of code that needs to go into checking to be sure Form B is ready to receive the data from Form A. Questions like "has the user changed the data on Form B and should it be saved before we send data from From A?" have to be asked.

Without knowing more about how your users are using the forms (e.g. are the forms strickly data entry (new records), or will they use Form A to initiate a lookup and do you want to have form B automatically show information related to form A) and why you have chosen to use two forms instead of master and sub (child) form, there's really not much I can do other than tell you the code that will do what you asked which was to "auto-populate the data from form A to form B".

pactite June 4th, 2005 03:02 PM

Mr. Weer,

Again, thank you for your assiatance and if you are still interested in providing more assistance, please read on.

Concerning user interface, Form A is the first user entry point and the only data entry point from the switchboard. The user will not have access to Form B until they have entered all the information on Form A and the Form B only opens when, the user answers a question on a yes or no button. If they click, "yes," the form B opens and closes the Form A. If they click, "No," then the Form A either provides an option of going to a new record on the Form or closing the form.

Hope this shed some light into the issue.

All times are GMT -4. The time now is 10:14 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.