Results 1 to 4 of 4
  1. #1
    Jojojo is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Oct 2011
    Posts
    46

    Red face Limit records entered in subform based on main form

    I would like to control/limit the number of records that can be entered into a subform based on a choice the user makes in the main form



    There is a combo box called FeeScheduleID on the main form. There are 8 choices. I'd like, if the user chooses option 1, they can only add 1 record. If they choose option 2, they shave to enter 2 records, up to 5. The last 3 choices I would like not to have a limit. The subform is data sheet style, where the user selects their class option from a combo box.

    Right now the form/subform is fully functional, it just doesn't control the number of records that can be entered and I'm noticing a lot of user error, like choosing option 2 and entering 1 or 3 records then in the subform. have no idea how to do the code on this. I thought it would be like an if then statement??

  2. #2
    hertfordkc is offline 18 year novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    481

    You'll probably need to get comfortable with VBA.

    On your main form, you could have the Onclick event for the option set the number of additions allowed in a hidden textbox.
    In the subform, the Onload event sets the records added to zero. The afterupdate event adds one to the records added and closes the subform (or sets the addition property to false) when it reaches the limit.

  3. #3
    Jojojo is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Oct 2011
    Posts
    46
    Quote Originally Posted by hertfordkc View Post
    On your main form, you could have the Onclick event for the option set the number of additions allowed in a hidden textbox.
    In the subform, the Onload event sets the records added to zero. The afterupdate event adds one to the records added and closes the subform (or sets the addition property to false) when it reaches the limit.
    I think I'm following the idea, but I don't have a clue where to start with figuring out th code to do all of that... Would you be able
    to elaborate at all?

  4. #4
    hertfordkc is offline 18 year novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    481

    What you want doesn't require a lot of code.

    Quote Originally Posted by Jojojo View Post
    I would like to control/limit the number of records that can be entered into a subform based on a choice the user makes in the main form

    There is a combo box called FeeScheduleID on the main form. There are 8 choices. I'd like, if the user chooses option 1, they can only add 1 record. If they choose option 2, they shave to enter 2 records, up to 5. The last 3 choices I would like not to have a limit. The subform is data sheet style, where the user selects their class option from a combo box.
    With the main form in design mode, add a textbox and set its visible property to false.
    Assume its name is 'TextBox20.
    Then select 'FeeScheduleID' and look at its property sheet. You should see a "Click" event. On the right of that line is an ellipsis (...). Click on the ellipsis and select VBA code. The VBA screen should appear with
    Sub FeeScheduleID_OnClick()
    End Sub
    Insert something like this:
    TextBox20.value = FeeScheduleID.Option ' This will depend on details of your combo box
    If TextBox20.value > 5 then Textbox20.value = 1000

    You've set the maximum number of records allowed.

    Right now the form/subform is fully functional, it just doesn't control the number of records that can be entered and I'm noticing a lot of user error, like choosing option 2 and entering 1 or 3 records then in the subform. have no idea how to do the code on this. I thought it would be like an if then statement??
    In the subform in design view in the property sheet, find the 'afterupdate' event, and go to the VBA screen.
    Insert
    ParentForm.Textbox20.valule = ParentForm.Textbox20.valule - 1
    If ParentForm.Textbox20.valule <= 0 then me.visible = false

    I've abstracted something that demands attention to detail. Expect errors and test each step, e.g. don't make the textbox invisible until you see that it is getting the expected value. If your subform displays existing records in addition to a new record, I believe the afterupdate event will fire if the user selects an existing record, and then changes focus to another record. If so, you may have to look at the afterupdate event for another control. You may want to make the subform visible again, which could be done in the main form's onclick event.
    Patience.

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

Similar Threads

  1. Replies: 4
    Last Post: 10-18-2011, 10:18 AM
  2. Subform Combobox based on Main form combo box
    By accessmom in forum Forms
    Replies: 5
    Last Post: 02-21-2011, 07:02 AM
  3. Subform Filter based on Main Form Information
    By james.carpenter2 in forum Forms
    Replies: 0
    Last Post: 02-16-2011, 09:55 PM
  4. Replies: 1
    Last Post: 11-16-2010, 08:42 AM
  5. Replies: 0
    Last Post: 06-23-2009, 03:01 PM

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