Connecting popup forms to parent forms

J

Jacqueline

I am using/learning 2007, I created one master form with several popup forms
that feed my various tables.

The master form is Grants with all others popups as then infor is required.
I was able to attach the popups to the master with this code in the GrantID
field which is the PK for all the tables, to auto populate the GrantID field
when one of the popups are accesse for the current record:

=[Forms]![frmGrants]![GrantID]

It apears to work, when I access the popup from the main grant form the
current record GrantID is filled into the popup GrantID field.

However, when I try to complete the popup and return to the main form I get
a Null Primary key error report. So even though the field looks like it
filled in correctly it is not populating the table.

Help, I have thought myself into several circles...
Thanks in advance
 
J

John W. Vinson

I am using/learning 2007, I created one master form with several popup forms
that feed my various tables.

The master form is Grants with all others popups as then infor is required.
I was able to attach the popups to the master with this code in the GrantID
field which is the PK for all the tables, to auto populate the GrantID field
when one of the popups are accesse for the current record:

=[Forms]![frmGrants]![GrantID]

It apears to work, when I access the popup from the main grant form the
current record GrantID is filled into the popup GrantID field.

However, when I try to complete the popup and return to the main form I get
a Null Primary key error report. So even though the field looks like it
filled in correctly it is not populating the table.

Help, I have thought myself into several circles...
Thanks in advance

The expression above is just DISPLAYING the GrantID from frmGrants. It's not
populating the table because the control's Control Source property is the
expression, not the fieldname.

Rather than using popup forms, consider using Subforms instead. These will
fill in and synchronize the GrantID automatically with no code at all. If you
want to do it with popup forms you will need code to pass the GrantID in the
OpenArgs argument of the OpenForm method in the click event of the command
button which opens the form, and in the popup form's Open event to retrieve
that value and store it in the table... gets a bit complex!
 
J

Jacqueline

John,
Thanks for the information, I was afrid it could not be as easy as I had
first thought. I am pretty versed in using events and creating macros and
just a bit of VB. Can you walk be through the steps to code the popups as you
indicated?

I wanted to keep the DB to one main form and make it as unclutered as
possible. I can go back to the subform things but would like to learn the
method you indicated.
Thanks in advance.
--
Jacqueline


John W. Vinson said:
I am using/learning 2007, I created one master form with several popup forms
that feed my various tables.

The master form is Grants with all others popups as then infor is required.
I was able to attach the popups to the master with this code in the GrantID
field which is the PK for all the tables, to auto populate the GrantID field
when one of the popups are accesse for the current record:

=[Forms]![frmGrants]![GrantID]

It apears to work, when I access the popup from the main grant form the
current record GrantID is filled into the popup GrantID field.

However, when I try to complete the popup and return to the main form I get
a Null Primary key error report. So even though the field looks like it
filled in correctly it is not populating the table.

Help, I have thought myself into several circles...
Thanks in advance

The expression above is just DISPLAYING the GrantID from frmGrants. It's not
populating the table because the control's Control Source property is the
expression, not the fieldname.

Rather than using popup forms, consider using Subforms instead. These will
fill in and synchronize the GrantID automatically with no code at all. If you
want to do it with popup forms you will need code to pass the GrantID in the
OpenArgs argument of the OpenForm method in the click event of the command
button which opens the form, and in the popup form's Open event to retrieve
that value and store it in the table... gets a bit complex!
 
J

John W. Vinson

John,
Thanks for the information, I was afrid it could not be as easy as I had
first thought. I am pretty versed in using events and creating macros and
just a bit of VB. Can you walk be through the steps to code the popups as you
indicated?

I wanted to keep the DB to one main form and make it as unclutered as
possible. I can go back to the subform things but would like to learn the
method you indicated.
Thanks in advance.

You can get an unclutterd look by using a Tab Control, with "mainform"
textboxes and other controls on the first page and a Subform on each
additional page. But to use popup forms, use code like this in the command
button which opens the form:

Private Sub cmdOpenFirstPopup_Click()
DoCmd.OpenForm "FirstPopup", WhereCondition := Me!GrantID, _
OpenArgs := Me!GrantID
End Sub

and in FirstPopup's Open event

Private Sub Form_Open(Cancel as Integer)
If Me.OpenArgs & "" <> "" Then ' was an OpenArgs passed?
Me!ContactID.DefaultValue = Chr(34) & Me.OpenArgs & Chr(34)
End If
End Sub

Totally bare bones, no error checking, no flexibility... but should get you
started.
 
J

Jacqueline

Thanks John, I will play with this, it should get me started. I will either
learn how to do this or as you suggested go back to subforms.

Thanks for all you help
 

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