Results 1 to 3 of 3
  1. #1
    Traceyann is offline Novice
    Windows XP Access 2010 64bit
    Join Date
    Aug 2012
    Posts
    7

    Create form to enter data for many to many relationship

    Hi
    I am new here and to ms access so I apologise for my lack of knowledge. Ive scoured the forum looking for answer but to no avail so heres hoping someone can help me out. I have 3 tables. Suppliers, Products and a link table Suppliers_link_Products.The link tables have foreign keys relating to the primary key fields in the main tables One supplier can easily have many products and one product can have many suppliers thus the reason for a junct table. What I want to do is have a form where I can enter a new supplier, and then choose a product from a drop down box. Ive tried combo box but I then have two problems 1/when I choose a product from the list it then doesnt place this back in the correct table and 2/ the supplier could supply 5 products?
    Once I have this sorted I then want to do the same for the products. ie Enter a new product then be able to choose its possible suppliers. I have no knowledge of coding whatsoever so need something idiot proof!
    Thanks in advance

  2. #2
    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,726
    I have a situation of Tutors and Courses. To identify which Tutors can teach which Courses is a M:M.
    Attached jpg show the Form with combos for Courses, and combo for Tutors.
    The junction table is TutorCanTeachJunction. It has Id (autonumber PK) and a Unique index on CourseId and TutorId to prevent duplicates.

    I'm sure you can use similar approach.

    Good luck with your project.


    PS:
    Here is the code behind the "Add Tutor Teaches Course" button

    Code:
    '---------------------------------------------------------------------------------------
    ' Procedure : btnTeaches_Click
    ' Author    : Jack
    ' Date      : 12-10-2011
    ' Purpose   :  To populate TutorCouldTeachJunction Table with
    ' the id of the tutor and the id of the Course involved.
    'Unique index on TutorId & CourseId to prevent duplicates.
    '---------------------------------------------------------------------------------------
    ' Last Modified:
    '
    ' Inputs: N/A
    ' Dependency: N/A
    '--------------------------------------------------------------------------
    '
    Private Sub btnTeaches_Click()
       On Error GoTo btnTeaches_Click_Error
    
    On Error GoTo Err_btnTeaches_Click
    
    Dim SQL As String
    SQL = "Insert Into TutorCanTeachJunction(TutorId,CourseId) " _
        & "VALUES (" & Me.Combo0 & "," & Me.Combo3 & ")"
    Debug.Print SQL
    CurrentDb.Execute SQL, dbFailOnError
    
    Exit_btnTeaches_Click:
        Exit Sub
    
    Err_btnTeaches_Click:
        MsgBox Err.Description
        Resume Exit_btnTeaches_Click
    
       On Error GoTo 0
       Exit Sub
    
    btnTeaches_Click_Error:
    
        MsgBox "Error " & Err.number & " (" & Err.Description & ") in procedure btnTeaches_Click of VBA Document Form_frmTutorTeachesCourse"
        
    End Sub
    Attached Thumbnails Attached Thumbnails CoursesTutorsManyToMany.jpg  

  3. #3
    Traceyann is offline Novice
    Windows XP Access 2010 64bit
    Join Date
    Aug 2012
    Posts
    7
    Thank you will have a go

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

Similar Threads

  1. Replies: 1
    Last Post: 07-16-2012, 02:10 PM
  2. Can't enter or choose data in form
    By DMJ in forum Forms
    Replies: 3
    Last Post: 05-08-2012, 05:23 PM
  3. Replies: 4
    Last Post: 02-27-2012, 10:29 AM
  4. Using composite keys to enter data in a form
    By kymmyg in forum Database Design
    Replies: 2
    Last Post: 09-08-2010, 01:20 PM
  5. can't enter data in some form fields
    By ashiers in forum Forms
    Replies: 1
    Last Post: 09-18-2008, 12:37 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