Results 1 to 4 of 4
  1. #1
    tim_tims33 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Dec 2011
    Posts
    62

    How to prevent a record being inserted/accepted based on a comparison value in a textbox

    Hi,

    I'm building a very basic booking system for a leisure club. A facility (a simple room in the leisure club) has a max capacity (e.g. 20 people)
    The problem is that the form allows infinite number of bookings for a facility (See the sub-form below)


    Click image for larger version. 

Name:	form_Capture.JPG 
Views:	20 
Size:	36.8 KB 
ID:	36456

    In the sub-form, MemberID 4 is making a booking for a group size of 19. This is acceptable as the MaxCapacity for this facility is 20. However, MemberID has booked in a further 2 people, which is invalid.

    I have a Macro which I've attached to various events (Before Insert, After Insert, Before UPdate, After Update....) but none work!

    Here is the macro below:


    Click image for larger version. 

Name:	Macro_capture.JPG 
Views:	20 
Size:	18.2 KB 
ID:	36457

    Unforunately, more bookings can be made even if the Max Capacity has been exceeded!

    I think the key to this problem is getting the correct Event to trigger the macro...?

    When making a group booking, a MemberID is entered along with the number in the group they are booking in. Here is tbl_Group:


    • ClassID (Num)


    • MemberID (Num)


    • GroupSize (Num)


    Here is tbl_Facility:


    • FacilityID (Num)
    • Name (Text)


    • MaxCapacity (Num)


    Please help me, if you can, to reach a solution whereby if the total of entered [GroupSize] values exceeds [MaxCapacity], the system won't allow it.

    thanks

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Seems BeforeUpdate is the appropriate event to validate data.

    Certainly if the availability is not less than 1, the code will allow the booking record for any size group.

    Since the record is not yet committed, compare GroupSize to txtSpaceRemaining:

    If Forms!frm_Class!subformname.Form!txtGroupSize > Forms!frm_Class!txtSpaceRemaining Then

    I don't use macros, only VBA.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    tim_tims33 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Dec 2011
    Posts
    62
    Quote Originally Posted by June7 View Post
    Seems BeforeUpdate is the appropriate event to validate data.

    Certainly if the availability is not less than 1, the code will allow the booking record for any size group.

    Since the record is not yet committed, compare GroupSize to txtSpaceRemaining:

    If Forms!frm_Class!subformname.Form!txtGroupSize > Forms!frm_Class!txtSpaceRemaining Then

    I don't use macros, only VBA.
    June, interested to see what a VBA solution would look like for this... would you be able to provide a 'rough' idea for me?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    You could convert the macros to VBA https://support.office.com/en-us/art...ertmacrostovba

    Then replace the If line.

    Be sure to use a copy of your db to try this.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 11
    Last Post: 07-09-2014, 09:50 AM
  2. Replies: 3
    Last Post: 01-14-2014, 04:17 PM
  3. record time based on option using textbox
    By stoey in forum Programming
    Replies: 2
    Last Post: 04-14-2011, 08:43 AM
  4. Updating record based on textbox entry
    By timmy in forum Programming
    Replies: 16
    Last Post: 04-06-2011, 12:05 AM
  5. Replies: 7
    Last Post: 04-27-2010, 10:29 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