Thread: Adding New Record To Form Using Junction Table
Started 1 month, 3 weeks ago by Kevsim
I have a table called Fix and another called Documentation. These 2 tables are connected to each other through a junction table which has the keys FixID and DocumentationID. There is a form called Fix, the form works well with all the Fix controls, add new record, edit record etc. I have added a combo box called Documentation (to update the Documentation table) along with all the Fix controls....
Have you tried an append query? CODE Dim strSQL As String strSQL = "INSERT INTO tblDocumentation(Key) VALUES(" strSQL = strSQL & Me.Key & ") DoCmd.RunSQL strSQL Randy
randy700' Thanks for the info. Where the code states "Key", what values do I put in there? Also to explain a little further, Table T_Fix has FixID and some other foreign keys, Table T_Link has FixID and DocumentationID only, Table T_Documentation has DocumentationID only. I would appreciate some more information. kevsim
Replace "Key" in my code with the name of the key field in your table. Me.Key signifies the control on the form that is bound to the key field in your query/table. You can continue to add more fields as necessary, making sure you use the proper delimitors. Randy
randy700, Thanks for the info provided. I have changed the code a little as I want to put a key value in each key field in the Junction table. When I run the code I receive an error "Run Time Error 3450, Syntax error in query, incomplete query clause" My code is as follows- strSQL = "INSERT INTO tblT_Junction.(FixID), tblT_Junction.(DocsID)VALUES(" strSQL = strSQL & Me.[Text188] & ")" & Me.[...
randy700, Once more thank you for the help. I added the comma to the code but still receiving the same error. When holding the cursor over strSQL the second value was separated by a comma but did not have a leading bracket. I added a bracket after the comma and now both values are enclosed, I thought this may have been the problem, but still receiving the error "Run Time Error 3450, Syntax ...
randy700, Thank you for all your help, success at last. I have corrected the SQL statement, I had the table mentioned twice in INSERT INTO and I had to remove the middle brackets between text and combo boxes. Find revised code - strSQL = "INSERT INTO T_Junction(FixID,DocsID)VALUES (" strSQL = strSQL & Me.[Text188] & "," & Me.[Combo350] & " );" DoCmd.RunSQL strSQL All working OK. kevsim
randy700, Thank you for all your help, success at last. I have corrected the SQL statement, I had the table mentioned twice in INSERT INTO and I had to remove the middle brackets between text and combo boxes. Find revised code - strSQL = "INSERT INTO T_Junction(FixID,DocsID)VALUES (" strSQL = strSQL & Me.[Text188] & "," & Me.[Combo350] & " );" DoCmd.RunSQL strSQL...
Add a comma... CODE strSQL = "INSERT INTO tblT_Junction.(FixID), tblT_Junction.(DocsID)VALUES(" strSQL = strSQL & Me.[Text188] & ") , " & Me.[Combo350] & ")" This assumes both fields are numeric. For text, you need to add single quotes... CODE strSQL = "INSERT INTO tblT_Junction.(FixID),...
Thread profile page for "Adding New Record To Form Using Junction Table" on http://www.tek-tips.com.
This report page is a snippet summary view from a single thread "Adding New Record To Form Using Junction Table", located on the Message Board at http://www.tek-tips.com.
This thread profile page shows the thread statistics for: Total Authors, Total Thread Posts, and Thread Activity