Popup Subform linked to MainForm (1 Viewer)

alanij

Registered User.
Local time
Today, 15:45
Joined
Nov 20, 2008
Messages
12
I am trying to create a command button that allows a subform to pop up in my Main form (parent form).

The relationship between this 'Parent' and 'Child' is a one-to-one relationship and when the subform pops up it won`t relate this subform to the 'parent' form. i.e. i would expect the PrimaryKey Autonumber to automatically appear as it would if the subform was normally visible on the Main Form.

I then get a message saying 'Index or Primary key cannot contain Nll Value' when i try to close the popup subform. The data type in the Table for both are correct.

I`m fairly new to Access so any advice would be appreciated.
 

Singh400

Registered User.
Local time
Today, 15:45
Joined
Oct 23, 2008
Messages
138
You have defined a field as a PK, which requires to be filled in when another other field on the form is edited and at the same time you are leaving the PK field blank. Which is not allowed.

I'd go back and visit your table design and relationship.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 15:45
Joined
Sep 12, 2006
Messages
15,613
how do you get a 1-1 relationship

these are very specialised, and abnormal

do you just mean that in some cases, you want to see additional fields?
 

alanij

Registered User.
Local time
Today, 15:45
Joined
Nov 20, 2008
Messages
12
I have 6 tables which are quite specific so have kept them separate rather than put them all in one table. Therefore I have joined them by a unique number to each record by a 1:1 relationship to each table i have.

I was hoping to have my 'main table' as the Parent Form, and then a few of the other tables available as a 'popup' by use of a command or toggle button. I will need to enter data into the popup but when I try to create this the popup doesn`t reference to the Main form even though the relationships are setup.
 

DevastatioN

Registered User.
Local time
Today, 12:45
Joined
Nov 21, 2007
Messages
242
I have done something very similar in a recent project.

Your main table should have a combobox for "type of record" or whatever you are dealing with, each specific type should look to a certain table. If this does not fit your case, then you would need multiple buttons on which subform to show.

When you say "popup on parent form" I assume you mean on the same form, which can be done by visible property, if you mean that you want another form to literally pop up, that can be done also (but I won't put that in this post).

Create the subform on your parent form (I named mine sfrm), linking it to a subform with the primary keys. Then edit the properties of the subform so that the source object is blank (removes the subform linking, because this has to be done with code), and set the visible property to false.

On your form add a button, with the following code that you can manipulate:

DoCmd.RunCommand acCmdSaveRecord

If Me.DocType = "Periodical" Then
Me.sfrm.SourceObject = "frmMainItems_sfrmPeriodicals"
Me.sfrm.Visible = True
ElseIf Me.DocType = "Commitment" Then
Me.sfrm.SourceObject = "frmMainItems_sfrmCommitments"
Me.sfrm.Visible = True
Else
Me.sfrm.Visible = False
Me.sfrm.SourceObject = ""
End If

Notice that the record should be saved before the subform is added, so that the main form has a primary key to link to.

The if statement checks DocType for the type of record, to decide which subform to bind to. If you don't have a document type and want a button for each subform, you just need the visible and SourceObject to be filled.

Hope this is helpful to what you are trying to do.
 

DevastatioN

Registered User.
Local time
Today, 12:45
Joined
Nov 21, 2007
Messages
242
Here is an example of what I think you want.
 

Attachments

  • 1on1.zip
    29.2 KB · Views: 1,158

ulieq

Registered User.
Local time
Today, 08:45
Joined
Dec 15, 2011
Messages
28
I'm looking for the same result (but with a popup subform) as the 1on1 AND as a macro, not vba. Does anyone know how to do this? Thanks.
 

Users who are viewing this thread

Top Bottom