Passing data from one form to another

G

Guest

I have a created a form that will be used to update existing records as well
as create new records using all the fields from an existing record except for
one field. I created an 'Add' command button that opens another form that I
want to populate with most of the data from the fields (or text boxes) of the
first form, then supply the data for the different field from a drop down
list, then save the form.

This works for the first record on the first form. But if I navigate to a
different record on the first form, the data from the first record on the
first form is carried to the second form instead of the data from the just
"navigated to" record. I am currently populating the fields on the second
form in the Load event of the second form by moving what I think is the
database field to a variable, then into the second forms text box.

How can this data be "passed"? What record can I expect to be current on the
second form after navigating forward on the first form?

Bev
 
K

kingston via AccessMonster.com

Use the OnCurrent event of the first form instead of the second form's OnLoad
event (get rid of that code). You may want to add some code to check that
the second form is open before setting its values.
 
G

Guest

I tried this and am getting essentially the same results. Since I do not
understand when the next record is "read" and available when navigating to
the second form, it is hard to determine where and when the record is
present. Can you provide some guidance with this or direct me to a good
resource for this kind of information?

Bev
 
K

kingston via AccessMonster.com

The OnCurrent event happens when you move to a record. So, I would use this
on the first form. Thus when you move to a record, the OnCurrent event
procedure should do the following:

1) Check to see that form 2 is open:
If CurrentProject.AllForms("Form2Name").IsLoaded = True Then...

2) Assign values in form 2 based on current record of form 1:
Forms!Form2Name!Field1 = Me.Field1

Get rid of the existing OnLoad code for form 2 or modify it so as to not
overwrite the results of the OnCurrent procedure. Go into debug mode and
step through the code to make sure that something else isn't interfering with
the value assignments (e.g. you're trying to assign a Null value). The above
code works by itself. I'm not sure what you mean by "when the next record is
read", but you can find out more about form events and their sequence in
Access help under "Find out when events occur."

greyhound said:
I tried this and am getting essentially the same results. Since I do not
understand when the next record is "read" and available when navigating to
the second form, it is hard to determine where and when the record is
present. Can you provide some guidance with this or direct me to a good
resource for this kind of information?

Bev
I have a created a form that will be used to update existing records as well
as create new records using all the fields from an existing record except for
[quoted text clipped - 14 lines]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top