andymartin3186
New member
- Local time
- Today, 19:43
- Joined
- Dec 10, 2024
- Messages
- 21
Many thanks, this worked brilliantly. The code I used at the end wasWhen you press the button - triggering the On Click event obtain the PartID, and the JOBID. In your code construct a SQL INSERT statement, which you then execute:
INSERT INTO table_name (column1, column2, column3) VALUES ('value1', 'value2', 'value3');
so it might be
Code:intPartID = me.PartNo intJobID = me.JobID strsql = "INSERT INTO JobParts (PartID, JobID) Values ( " & intPartID & ", " & intJobID &) debug.print strsql Docmd.runsql strsql
you need to dim the variables, and you should use Debug.print strsql to check it is properly formed / valid before executing then comment it out
And when it is working to your satisfaction you may then want to turn off the warning message confirming are you sure you want to insert the record, immediately before the Docmd and turn warnings on again immediately after.
Dim intPartID As Integer
Dim intJobID As Integer
intPartID = Me.PartID
intJobID = Forms![Job Form]![JobNumber]
strsql = "INSERT INTO JobParts (PartID, JobID) Values ( " & intPartID & ", " & intJobID & ")"
Debug.Print strsql
DoCmd.RunSQL strsql
Forms![Job Form]![Job Subform].Requery
End Sub