Linking two Forms

  • Thread starter Secret Squirrel
  • Start date
S

Secret Squirrel

I have a form where users will do all their data entry. I have another form
where they can add additional information for that particular record. The can
click on a command button to access this other form. But when they click on
this button I want to be able to carry over the Primary key field (the
autonumberID) and have it populate a field on this other form. This way I can
tie the two tables together. But here's the catch, I want people to also
access this other form via the switchboard as well without carrying over the
Primary Key from that main form. There are two way to create a record on this
form. One is directly and the other is through the main data entry form.
There are two ways a record can be generated. Am I making sense here?
 
J

Joan Wild

From form one...
DoCmd.OpenForm "SecondForm", , , "[SomeID] = Forms![FormOne]![SomeID]"
 
S

Secret Squirrel

But will that second form always open to that specific record if it's tied
into the first record?

Joan Wild said:
From form one...
DoCmd.OpenForm "SecondForm", , , "[SomeID] = Forms![FormOne]![SomeID]"


--
Joan Wild
Microsoft Access MVP

Secret said:
I have a form where users will do all their data entry. I have
another form where they can add additional information for that
particular record. The can click on a command button to access this
other form. But when they click on this button I want to be able to
carry over the Primary key field (the autonumberID) and have it
populate a field on this other form. This way I can tie the two
tables together. But here's the catch, I want people to also access
this other form via the switchboard as well without carrying over the
Primary Key from that main form. There are two way to create a record
on this form. One is directly and the other is through the main data
entry form. There are two ways a record can be generated. Am I making
sense here?
 
J

Joan Wild

Yes

--
Joan Wild
Microsoft Access MVP

Secret said:
But will that second form always open to that specific record if it's
tied into the first record?

Joan Wild said:
From form one...
DoCmd.OpenForm "SecondForm", , , "[SomeID] =
Forms![FormOne]![SomeID]"


--
Joan Wild
Microsoft Access MVP

Secret said:
I have a form where users will do all their data entry. I have
another form where they can add additional information for that
particular record. The can click on a command button to access this
other form. But when they click on this button I want to be able to
carry over the Primary key field (the autonumberID) and have it
populate a field on this other form. This way I can tie the two
tables together. But here's the catch, I want people to also access
this other form via the switchboard as well without carrying over
the Primary Key from that main form. There are two way to create a
record on this form. One is directly and the other is through the
main data entry form. There are two ways a record can be generated.
Am I making sense here?
 
J

Joan Wild

Sorry I was confused with another thread. You are putting that code in the
first form's module. So it will only apply when you open the second form
from the first.

It's not 'tied' to the first record. If you open your first form and go to
the 6th record (ID=559 for eg.), and you hit the button to open the second
form; the second form will open to show you related information for ID=559.

Perhaps I misunderstand your question.


--
Joan Wild
Microsoft Access MVP

Secret said:
But will that second form always open to that specific record if it's
tied into the first record?

Joan Wild said:
From form one...
DoCmd.OpenForm "SecondForm", , , "[SomeID] =
Forms![FormOne]![SomeID]"


--
Joan Wild
Microsoft Access MVP

Secret said:
I have a form where users will do all their data entry. I have
another form where they can add additional information for that
particular record. The can click on a command button to access this
other form. But when they click on this button I want to be able to
carry over the Primary key field (the autonumberID) and have it
populate a field on this other form. This way I can tie the two
tables together. But here's the catch, I want people to also access
this other form via the switchboard as well without carrying over
the Primary Key from that main form. There are two way to create a
record on this form. One is directly and the other is through the
main data entry form. There are two ways a record can be generated.
Am I making sense here?
 
S

Secret Squirrel

Ok now I'm confused. ;-) I am putting this code in the first forms module?
Where exactly is that? The way you explained it below is exactly what I am
looking for.

Joan Wild said:
Sorry I was confused with another thread. You are putting that code in the
first form's module. So it will only apply when you open the second form
from the first.

It's not 'tied' to the first record. If you open your first form and go to
the 6th record (ID=559 for eg.), and you hit the button to open the second
form; the second form will open to show you related information for ID=559.

Perhaps I misunderstand your question.


--
Joan Wild
Microsoft Access MVP

Secret said:
But will that second form always open to that specific record if it's
tied into the first record?

Joan Wild said:
From form one...
DoCmd.OpenForm "SecondForm", , , "[SomeID] =
Forms![FormOne]![SomeID]"


--
Joan Wild
Microsoft Access MVP

Secret Squirrel wrote:
I have a form where users will do all their data entry. I have
another form where they can add additional information for that
particular record. The can click on a command button to access this
other form. But when they click on this button I want to be able to
carry over the Primary key field (the autonumberID) and have it
populate a field on this other form. This way I can tie the two
tables together. But here's the catch, I want people to also access
this other form via the switchboard as well without carrying over
the Primary Key from that main form. There are two way to create a
record on this form. One is directly and the other is through the
main data entry form. There are two ways a record can be generated.
Am I making sense here?
 
J

Joan Wild

OK, let's start from square one.

You wrote

"I have a form where users will do all their data entry. I have
another form where they can add additional information for that
particular record. The can click on a command button to access
this other form."

I'm referring to the code you have in the click event for this command
button. It should be something like
DoCmd.OpenForm "SecondForm", , , "[SomeID] = Forms![FormOne]![SomeID]"

You would substitute the name of your second form for SecondForm; the name
of the primary key field for SomeID.

How about you post what is currently in the click event for your command
button, and also the name of the primary key field in the one form and the
name of the foreign key in the second form.

--
Joan Wild
Microsoft Access MVP

Secret said:
Ok now I'm confused. ;-) I am putting this code in the first forms
module? Where exactly is that? The way you explained it below is
exactly what I am looking for.

Joan Wild said:
Sorry I was confused with another thread. You are putting that code
in the first form's module. So it will only apply when you open the
second form from the first.

It's not 'tied' to the first record. If you open your first form
and go to the 6th record (ID=559 for eg.), and you hit the button to
open the second form; the second form will open to show you related
information for ID=559.

Perhaps I misunderstand your question.


--
Joan Wild
Microsoft Access MVP

Secret said:
But will that second form always open to that specific record if
it's tied into the first record?

:

From form one...
DoCmd.OpenForm "SecondForm", , , "[SomeID] =
Forms![FormOne]![SomeID]"


--
Joan Wild
Microsoft Access MVP

Secret Squirrel wrote:
I have a form where users will do all their data entry. I have
another form where they can add additional information for that
particular record. The can click on a command button to access
this other form. But when they click on this button I want to be
able to carry over the Primary key field (the autonumberID) and
have it populate a field on this other form. This way I can tie
the two tables together. But here's the catch, I want people to
also access this other form via the switchboard as well without
carrying over the Primary Key from that main form. There are two
way to create a record on this form. One is directly and the
other is through the main data entry form. There are two ways a
record can be generated. Am I making sense here?
 
S

Secret Squirrel

Ok here is the code from my command button. It is what you said it should be
but when I key information on the second page and then exit out and go back
into it the data is blank. Almost like it's starting a new record.

Private Sub Command209_Click()
On Error GoTo Err_Command209_Click

DoCmd.OpenForm "frmCorrectiveActionRMA", , , "[RMA#] = Forms![2005
Form]![RMA#]"

Exit_Command209_Click:
Exit Sub

Err_Command209_Click:
MsgBox Err.Description
Resume Exit_Command209_Click

End Sub

My primary key on my first form is RMA#. The foreign key on the second form
is also RMA#. I have the foreign key linked to the first form's RMA#. Is that
correct also?

Joan Wild said:
OK, let's start from square one.

You wrote

"I have a form where users will do all their data entry. I have
another form where they can add additional information for that
particular record. The can click on a command button to access
this other form."

I'm referring to the code you have in the click event for this command
button. It should be something like
DoCmd.OpenForm "SecondForm", , , "[SomeID] = Forms![FormOne]![SomeID]"

You would substitute the name of your second form for SecondForm; the name
of the primary key field for SomeID.

How about you post what is currently in the click event for your command
button, and also the name of the primary key field in the one form and the
name of the foreign key in the second form.

--
Joan Wild
Microsoft Access MVP

Secret said:
Ok now I'm confused. ;-) I am putting this code in the first forms
module? Where exactly is that? The way you explained it below is
exactly what I am looking for.

Joan Wild said:
Sorry I was confused with another thread. You are putting that code
in the first form's module. So it will only apply when you open the
second form from the first.

It's not 'tied' to the first record. If you open your first form
and go to the 6th record (ID=559 for eg.), and you hit the button to
open the second form; the second form will open to show you related
information for ID=559.

Perhaps I misunderstand your question.


--
Joan Wild
Microsoft Access MVP

Secret Squirrel wrote:
But will that second form always open to that specific record if
it's tied into the first record?

:

From form one...
DoCmd.OpenForm "SecondForm", , , "[SomeID] =
Forms![FormOne]![SomeID]"


--
Joan Wild
Microsoft Access MVP

Secret Squirrel wrote:
I have a form where users will do all their data entry. I have
another form where they can add additional information for that
particular record. The can click on a command button to access
this other form. But when they click on this button I want to be
able to carry over the Primary key field (the autonumberID) and
have it populate a field on this other form. This way I can tie
the two tables together. But here's the catch, I want people to
also access this other form via the switchboard as well without
carrying over the Primary Key from that main form. There are two
way to create a record on this form. One is directly and the
other is through the main data entry form. There are two ways a
record can be generated. Am I making sense here?
 
J

Joan Wild

Secret said:
Ok here is the code from my command button. It is what you said it
should be but when I key information on the second page and then exit
out and go back into it the data is blank. Almost like it's starting
a new record.

Check the properties for the second form. Perhaps you have it set to 'Data
Entry' - yes. That will always open the form to a new record, and show no
existing records.
 
J

Joan Wild

OK, so we know the record is getting added. There must be something in the
code behind the second form that is not showing existing records. Can you
check the open/load/activate events to see?
 
S

Secret Squirrel

All the events on the second form are empty.

Joan Wild said:
OK, so we know the record is getting added. There must be something in the
code behind the second form that is not showing existing records. Can you
check the open/load/activate events to see?
 
J

Joan Wild

Let's see if I have this straight. You enter information in form 2. You
close it. You open the recordsource for form 2 and you see the just-entered
record. You open form 2, but don't see this information. Is that right?
 
S

Secret Squirrel

Yes that is correct.

Joan Wild said:
Let's see if I have this straight. You enter information in form 2. You
close it. You open the recordsource for form 2 and you see the just-entered
record. You open form 2, but don't see this information. Is that right?
 
J

Joan Wild

Problem solved. If anyone's still reading, there was a saved filter on the
second form. In addition there was an error of mine in an earlier post, and
also data type problems and control sources wrong. I also suggested using
the OpenArgs property to set the default value of the foreign key field in
the second form.
 
Top