Lukael,
Although you haven't told us explicitly and clearly what you are trying to accomplish in plain English, I have looked at your database and guessed that you are trying to populate the Junction table.
I created a Form, called frmToAddRecordToJunctionTable. It contains 2 comboboxes combo2 and combo4. Combo2 is populated with records from your Table1 -which is poorly named in my view. Combo4 is populated with records from your Table2 - which also is poorly named in my view.
When you select a FirstName value in combo2, and a Surname value from Combo4, you can add a new record to your JoinTable by clicking the command6 button which has a caption
"Click to Add This new Junction Table Record"
The click event has the following code.
Code:
Private Sub Command6_Click()
'This procedure is executed when the command6 button is clicked.
'You do this to add this coombination FirstName and Surname to the
'junction table which you have named JoinTable
Dim sql As String
On Error GoTo Command6_Click_Error
sql = "INSERT INTO JOINTABLE (ID1,ID2) VALUES (" & Me.Combo2 & "," & Me.Combo4 & ");"
MsgBox " New record is " & Me.Combo2.Column(1) & " " & Me.Combo4.Column(1) & vbCrLf _
& " which will be stored as " & Me.Combo2 & " ," & Me.Combo4 & " within the JoinTable"
CurrentDb.Execute sql, dbFailOnError
On Error GoTo 0
Exit Sub
Command6_Click_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Command6_Click of VBA Document Form_frmToAddRecordToJunctionTable"
End Sub
I changed a few things in your JoinTable. I added a composite unique index composed of fields ID1 and ID2. This will prevent duplicates in the JOINTABLE.
I added 2 queries to the database
qryShowAllJoinTableRecords ---shows all records as they exist in JoinTable
qryShowAllNamesAndSurnamesOfJoinTableRecords -- uses relationships to show the values of FirstName and Surname based on the record in the JoinTable.
You could add buttons to frmToAddRecordToJunctionTable to open these queries if you wanted.
A few points regarding your database and databases in general using MSAccess.
Name tables, fields and objects with meaningful names. Tables can be FirstNameTable or tblFirstName etc. Calling tables Table1 and Table2 does not communicate anything to readers, nor anyone who may be left to manage your database. Name forms with a meaningful name also --calling a form "Table1" is confusing to say the least. Better to give your objects unique names, but this comes with experience.
Similarly in JoinTable, you have 3 fields - ID, ID1 and ID2. Naming the ID field simply ID in all tables ill lead to confusion especially when you get to 20-30+ table databases. A best practice is to name the ID field with some representation of the table -- for example SurnameID, FirstNameID.
I did not rename your tables or fields. I left my combo2 and combo4 as Access named them. I do not use macros, and prefer vba. M$oft recommends use of Access/Office 32 bit unless you have special requirements.
As I said I'm guessing at your requirement. If I have guessed wrong, then I suggest you give a clear description of what you are trying to accomplish in simple, plain English --and use business terms not database or Access jargon.
Good luck with your project.