Results 1 to 2 of 2
  1. #1
    craigugoretz is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Feb 2015
    Posts
    9

    How to add programming to a subform?

    Hello,

    Part of this post was originally posted to the forms forum of this website. My question to it was whether I needed programming to make an idea of mine to work (see below). The answer I got was yes, I did indeed need programming. My question to this forum is what the programming would look like? Also, if there are alternate criteria besides the ones given below (to get a subform to "play well" with its parent form), I would be open to hearing it.

    Say for example I have the following table labeled Master:

    ID: autornumber
    Label: string



    2nd, I have the following table labeled Slave:

    ID: autonumber
    Label: string
    Xref: foreign key to Master.ID field

    In other words, there is a one to many relationship between Master and Slave. In both tables, all fields are required.

    3rd, I have a Master form with a Slave subform:

    Master form:
    ID: xxxxxxxxxxx
    Label: xxxxxxxxxxxxxxxx

    Slave subform:
    ID: xxxxxxxxxxxx
    Label: xxxxxxxxxxxxxxx
    Xref: *** combo box ***

    Finally, I need the Master form and Slave subform to have these properties:

    (1) For every record in the master form, a corresponding record must exist in the subform, based on the Xref foreign key.
    (2) I want to force the user to have to enter a Slave record at the same time they enter a Master record.
    This is before the Master record is saved and data entry moves on to a new record.
    (3) Also, I don't want the user to be able to go back to the Slave subform and delete all records.
    In other words, there is always at least one record in the Slave subform for a corresponding Master form record based on the Xref foreign key.
    (4) However, I want a delete button in the Master form that will delete all corresponding records in the Slave subform at the same time the Master record is deleted.

    Thanks kindly,
    Craig

  2. #2
    NTC is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Posts
    2,392
    your slave subform has the cross reference set up as part of its insert into the main form and so the xref field is not needed in it - and not sure why you would show it as a combobox - there is no choice involved unless you want an unbound subform but that really isn't the way to go usually.

    (1) For every record in the master form, a corresponding record must exist in the subform, based on the Xref foreign key.
    *** if this is your requirement then you will need to manage with code checking in the form or potentially auto insert a record - but it requires custom code in either case

    (2) I want to force the user to have to enter a Slave record at the same time they enter a Master record.
    This is before the Master record is saved and data entry moves on to a new record.
    *** seems like the same point as 1; pop up messages, labeling, control the movement to new records - you will need to apply those type techniques as suits your user experience

    (3) Also, I don't want the user to be able to go back to the Slave subform and delete all records.
    In other words, there is always at least one record in the Slave subform for a corresponding Master form record based on the Xref foreign key.
    *** allowing delete of some but not all is very tricky; again you will need design & to be running code that is checking and reacting to things; stopping all deletes by comparison is relatively simple

    (4) However, I want a delete button in the Master form that will delete all corresponding records in the Slave subform at the same time the Master record is deleted.
    *** set up your master/slave relationship to be 'cascade deletes' - that is a property in table relationships

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 12-15-2014, 05:26 AM
  2. VBA Programming
    By Leeselson in forum Programming
    Replies: 4
    Last Post: 06-06-2012, 05:08 PM
  3. Programming a subform usaing VBA
    By ruthib4 in forum Forms
    Replies: 1
    Last Post: 12-01-2011, 06:24 PM
  4. Programming
    By JLT in forum Programming
    Replies: 10
    Last Post: 04-14-2011, 10:07 AM
  5. VB Programming
    By mstefansen in forum Programming
    Replies: 4
    Last Post: 08-31-2009, 07:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums