Results 1 to 6 of 6
  1. #1
    5 Star Lounger
    Join Date
    Mar 2001
    Posts
    989
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Problem with linked forms (2000)

    I attempted to link two forms by means of a ProjectID primary key field. However, the second form didn't 'relate' to the first - the ProjectID field was blank when the second form was opened from the first. I think the problem is that I used the Lookup Wizard to relate the two tables together, so that the ProjectID field appears as a Combo Box on the second form. I tried changing it to a Text Box, using right-click/ Change To, but this didn't work.

    Can someone describe what this problem is likely to be? This relates to my recent thread on Record Conflicts. I resolved it by adding a Tab Control and using a subform rather than a second form, but I want to know what caused the initial problem. Andy.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Problem with linked forms (2000)

    What code do you use to open the second form from the first one?

    Does the second form have code in its On Open or On Load event?

  3. #3
    5 Star Lounger
    Join Date
    Mar 2001
    Posts
    989
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Problem with linked forms (2000)

    I've got a main table with Project information, and created a secondary table to log dated entries relevant to the main projects table. This has an ID field (AutoNumber) ProjectID, Date, Notes, etc. I then used the lookup wizard to relate the ProjectID to the ProjectID in the main table. So I'm creating a simple one-to-many relationship.

    I then built a tabular form for this new table. I then added a button to the main projects form, and used the Controls Wizard to add a command button which opens the secondary form, and indicated that the ProjectID on the main form links the two forms. However, when I click the button the second form opens with a blank ProjectID field. The code involved is the standard code generated by the Controls Wizard. Why are the two forms not linking correctly? Andy.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Problem with linked forms (2000)

    The Command Button Wizard only opens the secondary form with a filter (where-condition) to display only records whose ProductID corresponds to that on the main form. It doesn't set the default value for ProductID.

    Since the On Click code for the command button on the main form was generated by the wizard, it probably contains a line

    DoCmd.OpenForm stDocName, , , stLinkCriteria

    Edit this to the following:

    DoCmd.OpenForm stDocName, , , stLinkCriteria, , , Me!ProjectID

    Create an On Load event procedure for the secondary form:

    Private Sub Form_Load()
    If Not IsNull(Me.OpenArgs) Then
    Me!ProductID.DefaultValue = Me.OpenArgs
    End If
    End Sub

    This will test if an OpenArgs value was passed to the form, and if so, set it as Default Value for ProductID.

  5. #5
    5 Star Lounger
    Join Date
    Mar 2001
    Posts
    989
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Problem with linked forms (2000)

    Thank you, that makes a lot of sense. I resolved the problem initially by adding the fields for the secondary form onto a tabbed control of the main form. So how come, in this instance, it 'assumes' the ProjectID as a default value? This doesn't appear to be consistent behaviour. Andy.

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Problem with linked forms (2000)

    If you use a subform on a main form, they are linked together by the Link Master Fields and Link Child Fields properties. Access uses these to fill in the link field(s) for a new record in the subform automatically.

    If you call a stand-alone secondary form, it is not linked to the primary form, except for being opened in a special way. There is no link field, so Access has no way of filling in the ProjectID unless you tell it how explicitly.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •