Page 1 of 2 12 LastLast
Results 1 to 15 of 26
  1. #1
    jennolsen79 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Dec 2013
    Posts
    14

    So Lost! Creating a database from scratch for the first time!

    I have never designed a database before, so I am trying to teach myself now. The last time I used Access was many years ago, and now things look so much different.

    Here's what I'm trying to accomplish.



    My company needs to be able to track the classes an employee needs to take by position. It also needs to track when the class was last taken, and when they are due to recertify in that class.

    I've been able to import my employee list as a table, that includes ID#, Name, Dept, and Position.

    Now I need to be able to get a class list in there that indicates which positions are required to take the class. I then need to indicate the dates each employee has taken the applicable classes. This is where I'm lost... I'm not sure how to build a table(?) to get this information...

    Can someone help?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Consider:

    tblEmployees
    you have that

    tblClasses
    ClassID
    ClassName
    RecertFreq (in months or years)

    tblPositions
    PositionID
    PositionName

    tblPositionsClasses
    ClassID
    PositionID

    tblEmployeesClasses
    EmployeeID
    ClassID
    ClassDate

    Now various queries joining tables can provide the data analysis you require.
    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
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Roger Carlson has some tutorials you should go through. It will really help.
    http://www.rogersaccesslibrary.com/f...s_forum46.html



    Some hints
    Don't use special characters or spaces in object names only letters or numbers.... the underscore is acceptable if you must separate words.
    Don't use look up fields - different from lookup tables.


    See http://access.mvps.org/access/tencommandments.htm
    See http://access.mvps.org/access/lookupfields.htm

  4. #4
    jennolsen79 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Dec 2013
    Posts
    14
    Quote Originally Posted by June7 View Post
    Consider:

    tblPositionsClasses
    ClassID
    PositionID

    tblEmployeesClasses
    EmployeeID
    ClassID
    ClassDate
    I assume the "ID" are the various PK's associated with each table. Given that information, for the Positions/Classes Table, that is just a conglomeration of the PK's from both tables, with ClassID being used as frequently as needed? Wouldn't there also be a third column for the PK for this table?

    Also, for that final table, which would be like a class list, It would be acceptable to use the ClassName instead of the ClassID? Our classes don't have a specific ID so I'm letting Access autonumber them for the PK, so when we plug in a class that was completed, it would be by class name.

    Quote Originally Posted by ssanfu View Post
    Roger Carlson has some tutorials you should go through. It will really help.
    http://www.rogersaccesslibrary.com/f...s_forum46.html
    I did see that, and am in the process of going through some of it.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    The junction tables can have their own ID if you want but not necessary because they are not used as foreign key anywhere.

    Save ClassID unless class names are very short. Use multi-column combobox for user selection of class. ClassID will be hidden column and user will see the class name.
    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.

  6. #6
    jennolsen79 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Dec 2013
    Posts
    14
    Quote Originally Posted by June7 View Post
    The junction tables can have their own ID if you want but not necessary because they are not used as foreign key anywhere.

    Save ClassID unless class names are very short. Use multi-column combobox for user selection of class. ClassID will be hidden column and user will see the class name.

    So here's my stupid question of the day. I am going to have to take the time to list out each class and the position that quialifies for that class on the juntion table, correct? There's not a magic warn to wave? lol

    Oh, and how short is short for class names?

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    No shortcut. This is data entry, from scratch.

    Algebra, English, Biology are short. "How to succeed at business without really trying" is long but it could be a unique identifier if you want.

    Some would advocate a number primary key regardless because number values are supposed to index faster.
    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.

  8. #8
    jennolsen79 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Dec 2013
    Posts
    14
    Quote Originally Posted by June7 View Post
    No shortcut. This is data entry, from scratch.

    Algebra, English, Biology are short. "How to succeed at business without really trying" is long but it could be a unique identifier if you want.

    Some would advocate a number primary key regardless because number values are supposed to index faster.
    Thank you so much for your help. Off to data entry land I go!

  9. #9
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    This data model may help put some pieces in to context.

    Good luck with your project.
    Attached Thumbnails Attached Thumbnails EmployeesAndPositions_V0.jpg  

  10. #10
    Dal Jeanis is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    June - I always put a PK in my junction tables. It allows me to be absolutely certain which instance I am deleting when I have to clean up the database to kill accidental dups.

    jennolsen - as June says, most people think it's best practice to use a numeric key.

    One thing, though - you should not begin data entry until you have finished designing your database and posted it here to get it bulletproofed. You'll save yourself a lot of time and trouble to follow ssanfu's advice in post #3. The better your initial design, the less rework, so the less data entry.

    We can also show you some shortcuts.

  11. #11
    jennolsen79 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Dec 2013
    Posts
    14
    So here's a sample of what I've set up so far. I think I've got the tables correct...

    Next step is making queries? But I think my information is in more than 1 table.

    For an end result, I need to be able to know:

    Who is due to take a class. (ID, Name, Position, Class Name, and Due Date). It would be great if I could have this in a cross tab to make creating the class sign in lists easier.

    So any help on this next step is appreciated. I think once I've gotten through this first one, I'll be much more comfortable creating ones in the future.
    Attached Files Attached Files

  12. #12
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Did you work through the info suggested by ssanfu in #3?

    As for Roger Carlson's site, this is the tutorial I recommend regarding tables and relationships. Good luck.

  13. #13
    Dal Jeanis is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    Naming Conventions

    Avoid spaces in table names and field names - they complicate the VBA code and the SQL code. Most Access experts prefer using CamelCase - just capitalize the first letter of each word and run the words together. If you must have space between words, then use an underscore _.

    It's helpful to put the prefix tbl in front of tables, frm in front of forms, qry in front of queries. This is one of a number of competing standards, and you can find lots of others out there.

    When synonyms are available that are shorter and mean the same thing, the shorter word is preferred. tblStaff rather than tblEmployees might be an example, or tblRole or tblPosts rather than tblPositions. Your mileage may vary.

    Reserved words

    Name, Date, Time, Month, Year, Join, and a bunch of other words are reserved word in Access. Class, Frequency and Position, I'm not sure about. Best to avoid reserved words.

    Key Fields and Relationships

    The best practice is to use the primary key of a table as the foreign key on other tables. Using the text name of a Class as the foreign key would be problematic. At the very least, if you proceed in that way, you should change the fieldname Class to ClassName and establish an index on it.

    You should also make sure you use the exact same name for the same foreign key field in different files. Using ClassID in one place and Class in another will lead to confusion.

    Some programmers might use the name ClassPK (for example) on the tblClasses and ClassFK or ClassID as the foreign key, but the more common practice is to use ClassID in all places.

    Junction Table Names

    I prefer to avoid the practice of bumping the names of two related tables together for the name of the junction table. For instance, a table that shows the hierarchy of employees (who reports to whom) would be called employee_employee. Best practice is to name the junction table based on naming the relationship it define, such as tblReportsTo or tblWorksFor or tblManager.

    For example, the table that indicates an Employee has taken a class is currently named EmployeeClasses. My preference would be for a name like tblClassesTaken or tblClassesCompleted.

    The table that shows what classes are required for a position, instead of PositionsClasses, could be either tblClassesRequired or tblPositionRequirements.

    Code:
    tblEmployees
      EmpID      autokey
      DeptID     FK to tblDepts
      PostID     FK to tblPositions
    
    tblPositions
      PostID     autokey
      PostName   Text
    
    tblClasses
      ClassID    autokey
      ClassName  Text
      Frequency  (Type?)  
    
    tblClassesTaken
      TakenID    autokey
      ClassID    FK to tblClasses
      EmpID      FK to tblEmployees
      takenDate  Date
    
    tblPositionRequirements
      ReqID      Autokey
      PostID     FK to tblPositions
      ClassID    FK to tblClasses
      Frequency  (Type?)
    I suspect that the frequency field may belong on tblPositionRequirements rather than tblclasses, since refreshers may have different frequencies depending on usage.

    Relationships

    There's a "Cycle" that goes from tblEmployees through classes and position back to the employee. This means that, in certain circumstances, you can ask the database a question, and it could give you different answers if you ask the question in a different order. This is especially a problem when your query has to do with finding things that have NOT happened, which is a significant concern in this database.

    I don't see a way to avoid this design, due to the purpose of the database. You just have to be aware that to pull records from both sides of that loop, you will need to make a separate query for each side of the loop, then join those two queries.

  14. #14
    jennolsen79 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Dec 2013
    Posts
    14
    I think I have all my tables. In fact, I think I need to have another table because employees can be promoted or transfer and may have a new set of classes they are required to take.

    However I'm having a problem creating a relationship.

    There should be a relationship between EmpID in tblEmployees and EmpID in tblEmployeeClasses. When I try to create the relationship I get the following: Click image for larger version. 

Name:	Relationship Error.jpg 
Views:	31 
Size:	53.8 KB 
ID:	14880

    Here's how my relationships look currently:
    Click image for larger version. 

Name:	Relationships.jpg 
Views:	30 
Size:	138.7 KB 
ID:	14881
    Let me know what I need to do to fix it.

  15. #15
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    The error message is telling you that there is data in "tblEmployeeClasses.EmpID" that is not in "tblEmployees.EmpID".
    An example is if
    "tblEmployees.EmpID" has IDs 1, 2, 3 and
    "tblEmployeeClasses.EmpID has IDs 0, 1, 2

    "tblEmployees.EmpID" does not have an ID of 0, so referential integrity cannot be enforced.

    Solution: Delete all records from "tblEmployeeClasses", then create the relationship.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Lost and Found Database
    By Squigglethecow in forum Access
    Replies: 1
    Last Post: 09-19-2012, 08:42 PM
  2. Questionnaire DB from Scratch
    By jomby in forum Database Design
    Replies: 4
    Last Post: 05-18-2012, 01:20 AM
  3. Replies: 7
    Last Post: 08-04-2011, 07:49 PM
  4. Building a database from scratch
    By kookiethekat in forum Access
    Replies: 1
    Last Post: 01-20-2011, 06:35 AM
  5. Help w/ DB from scratch.
    By ellixer in forum Database Design
    Replies: 9
    Last Post: 11-30-2010, 10:44 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