Results 1 to 6 of 6
  1. #1
    vinh0105 is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    3

    Exclamation How to make constraint when putting records into Access table?

    I am developing a simple database for students to register courses using Microsoft Access 2010. I have 4 tables: Student, Register, Course, and Section (1 Course can have many Sections).



    Then, there is a criteria that a student can only take up to 6 courses. Hence, may I know that where and how can I include this constraint? I believe that it should be in the Macro (Before Change) of the table Register, but I have no idea about it.

    My relationship is: Student -> Register <- Section <- Course

    Here is my file: https://www.mediafire.com/?7oxbrhrrvhyh5bi

    Please help me with that! Thanks in advance

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    In the before update, you can check the count of records before.
    Change the 'where' filter to add all your conditions.

    Code:
    dim vWhere
    
    vWhere = "[student]=" & form!frmEntry!txtStudentID
    
    If dCount("*", "Course",vWhere ) > 4 then
        msgbox "Student already has 4 courses"
    else
        'allow addition of record
    endif

  3. #3
    vinh0105 is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    3
    Quote Originally Posted by ranman256 View Post
    In the before update, you can check the count of records before.
    Change the 'where' filter to add all your conditions.

    Code:
    dim vWhere
    
    vWhere = "[student]=" & form!frmEntry!txtStudentID
    
    If dCount("*", "Course",vWhere ) > 4 then
        msgbox "Student already has 4 courses"
    else
        'allow addition of record
    endif

    Hi, Thanks for your comment. However, I am using Microsoft Access 2010 and I cannot find anything called "Before update". Btw, I have posted my file in the link above, could you please have a look and give me an example with the file? Thanks in advance.

    I am really sorry for any inconveniences caused cuz I am a newbie in this field. Please help me with that!

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    The BEFORE UPDATE happens on the form. If you are entering records via form, using this action.

    I personaly do not used it...instead I have an unconnected form, and a save button
    the save button does the date validation (like you want)
    If all is good, it writes the record, if not gives a message.

  5. #5
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Your table structures leave a lot to be desired. Specifically, the PK/FK fields.
    Text type PK fields can be used, but they are more difficult to use (IMO). I prefer autonumber type PK fields.

    You should read these:
    Use Autonumbers properly http://access.mvps.org/access/general/gen0025.htm

    Autonumbers--What they are NOT and What They Are http://www.utteraccess.com/wiki/index.php/Autonumbers

    Microsoft Access Tables: Primary Key Tips and Techniques http://www.fmsinc.com/free/newtips/primarykey.asp

    BTW, you do not need the "BirthMonth" field in table "Students". It can be derived at any time by using the Month() function.


    Shouldn't table "Register" have a date field, "RegisterDate"? How will you know which year the student registered for??? And maybe a field for which semester?
    Are the courses/sections the same every year? Maybe a date field for what year the course is/was offered?

  6. #6
    vinh0105 is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    3
    Hi guys,

    Thanks so much for your help. I will consider to include all these things in the database

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

Similar Threads

  1. Access SQL Syntax For Creating a Table With a Default Constraint
    By crystalclear in forum Database Design
    Replies: 3
    Last Post: 09-22-2013, 02:24 AM
  2. Replies: 1
    Last Post: 08-14-2012, 02:43 PM
  3. Putting deifferent records into one record
    By Purple_Heart in forum Access
    Replies: 1
    Last Post: 08-12-2012, 12:05 PM
  4. Not able to make multiple entries (records) in the table
    By ramindya in forum Database Design
    Replies: 3
    Last Post: 03-04-2012, 12:53 PM
  5. Make Table Query not accepting new records?
    By access allowed in forum Queries
    Replies: 5
    Last Post: 11-08-2011, 07:29 PM

Tags for this Thread

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