Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2004
    Posts
    364

    Unanswered: Form with a Subform - having to click in the subform first to add records.

    I have a form with a linked subform on it. I also have a listbox from a seperate table on the form.

    To allow me to add records from the listbox into the subform I have to click the mouse inside the subform prior to selecting records from the listbox. If I dont do this I cannot add any records to the subform.

    Why am I having to click inside the subform first (is it to initialize the subform?), and is there a way of not having to click inside the subform first because it is a pain!

  2. #2
    Join Date
    Jan 2009
    Location
    Kerala, India
    Posts
    183

    Form with a Subform - having to click in the subform first to add records.

    All controls on the Main Form (including the Sub-Form) have an index number and normally the first field or control have the index number 0. If you want to work with any control (say a Textbox) you have to select it before entering/editing its contents.

    You have to make the Sub-Form active before you are able to work with controls within the Sub-Form that's why you are forced to click on it.

    Try changing the Index Number of the Sub-Form to 0 so that this will be the active control on the Main Form all the time. You can work with the controls within the Sub-Form directly.
    www.MsAccessTips.com (Learn MS-Access Tips & Tricks)
    Learn Advanced MS-Access Programming with sample VBA Code.

    All responses are based on Access 2003/2007

  3. #3
    Join Date
    May 2010
    Posts
    601
    Quote Originally Posted by moss2076 View Post
    I have a form with a linked subform on it. I also have a listbox from a seperate table on the form.

    To allow me to add records from the listbox into the subform I have to click the mouse inside the subform prior to selecting records from the listbox. If I dont do this I cannot add any records to the subform.

    Why am I having to click inside the subform first (is it to initialize the subform?), and is there a way of not having to click inside the subform first because it is a pain!
    The reason you must click in to the sub form is that will force the parent form to save the record.

    Since you are wanting to run code in the parent for to add record to the subform, you must first save the parent for form's record before you can add related records otherwise you get a Referential Integrity error.

    To force the record to be saved, in your command button's code add this before your VBA code to add the records to the related table:

    Code:
    If Me.Dirty Then Me.Dirty = False
    Since this is related to your other post:

    Multiselect Listbox question again

    I would urge you to keep followup posts there.
    Boyd Trimmell aka HiTechCoach HiTechCoach.com (free access stuff)
    Microsoft MVP - Access Expert
    BPM/Accounting Systems/Inventory Control/CRM
    Programming: Nine different ways to do it right, a thousand ways to do it wrong.
    Binary--it's as easy as 1-10-11

Posting Permissions

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