Results 1 to 7 of 7

Thread: Linking forms

  1. #1
    Join Date
    Sep 2002
    Posts
    79

    Unanswered: Linking forms

    Is there a way to create a sub-form but, to not have it in the main form?

    Basically, I have crated a form called “Customers” and a sub-form called “Invoices” and they are linked by “Customer ID” – I have a Customer ID field in my sub-form, so, in the sub-form I have two ID fields – One is Invoice ID and the other is Customer ID.

    What I want to do is to be able to go into the “invoice” form by clicking a button in the “customers” form and have the “invoice” form open on the customer ID I clicked the button from.

    So If I was in record #4 (Customer ID #4) and I click the button, for the invoice to open in Customer ID #4 also, so I can view all invoices for customer ID #4 only and not other customer.

    Can this be done? Can it be done by using macros?

    Any advise is greatly appreciated.

  2. #2
    Join Date
    Apr 2002
    Posts
    139
    This functionality is included in the wizard in the toolbox that will help you when you create a command button for opening a form.

    Halfway in this wizard there is an option to choose from:
    "Show all records" and "Show only specific records"

    (Exact wording may differ since I'm not working in an English version at the moment).

    If you opt for ""Show only specific records", you get the possibility to connect the CustomerID fields.

    hth

  3. #3
    Join Date
    Sep 2002
    Posts
    79
    That works, but, it only does that for existing records not any new records.

    If Customer ID # 8 has 3 invoices, and I click the button to go into the Invoice sub-form, it will only link those three, but, when I create a 4th invoice, it will not have the Customer ID # in the field anymore – In that field it will only say “0” instead of “8” (for Customer ID #8)

    What should be done to have new records linked as well…

  4. #4
    Join Date
    Apr 2002
    Posts
    139
    Basically, you should just put your subform Invoices in the mainform Customers, that's the way it is regularly done.

    If for some reasons that's not wanted, you have alternatives:

    AA)
    Put the subform in the mainform, but hide it, or set it to minimal dimensions. On the command button you may set the subform to visible, or enlarge its dimensions.

    BB)
    You could also create a new, second mainform.
    In this new mainform you will only show the CustomerID, and further you include the subform with the invoice details in this second mainform.

    If you have set your relations right (one-to-many from Customer to Invoice), and if you have linked your subform in the right way to the second mainform, than you will be able to add new records.
    Have the button on your first mainform open the second mainform for the right record.

    hth

  5. #5
    Join Date
    Mar 2003
    Posts
    2

    Refresh database

    If you enter a new record, in the 'On Click' event enter this code befor you open the sub form - ' DoCmd.RunCommand acCmdRefresh'.

    this will refresh tour database and show all records.

    Michael Pakay

  6. #6
    Join Date
    Sep 2002
    Posts
    79
    Can you explain "AA" a bit more to me. I dont know how to hide it or set it to minimal demensions - How will that help with what I want to do?

    Originally posted by marion
    Basically, you should just put your subform Invoices in the mainform Customers, that's the way it is regularly done.

    If for some reasons that's not wanted, you have alternatives:

    AA)
    Put the subform in the mainform, but hide it, or set it to minimal dimensions. On the command button you may set the subform to visible, or enlarge its dimensions.

    BB)
    You could also create a new, second mainform.
    In this new mainform you will only show the CustomerID, and further you include the subform with the invoice details in this second mainform.

    If you have set your relations right (one-to-many from Customer to Invoice), and if you have linked your subform in the right way to the second mainform, than you will be able to add new records.
    Have the button on your first mainform open the second mainform for the right record.

    hth

  7. #7
    Join Date
    Jan 2003
    Location
    Aberdeen, Scotland, UK
    Posts
    168
    easy way:

    Put the code on a button:

    if not isnull(me.id) then
    docmd.openform"WhateverFormCalled",,"[Id] = " & me.id
    else
    docmd.openform"WhateverFormCalled",,,,acnewrec
    end if

    forms!WhateverFormCalled.Id.defaultValue = me.id

    This'll open a new form showing the correct data.
    J.

Posting Permissions

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