I have 2 tables:
Tbl_Task - Has all the tasks for a process (TaskNum is unique. TaskName is what i'm writing to Tbl_Proc)
Tbl_Proc - Will hold the status of each task for a customer
When a new customer is created, I'm using the forms on close event to write each task from Tbl_Task into Tbl_Proc. I'm using the customer name from the form to complete the record in the Tbl_Proc.
My thought is to use an integer to increment the TaskNum and assign that task numbers TaskName to the Tbl_Proc[ProcTaskName]. Then loop through all task numbers. As you can see, I'm stuck on the use of my integer variable.
Here is what I have. I can successfully write the Company name but I can't get the ProcTaskName:
Private Sub Form_Close()
On Error GoTo Err_Form_Close
Dim strCompany As String
Dim sqls As String
Dim x As Integer
strCompany = Me![CoName]
'MsgBox strCompany
x = 1
sqls = "INSERT INTO Tbl_Proc(ProcCo, ProcTaskName)" & _
"VALUES ('" & strCompany & "', SELECT TaskName FROM Tbl_Task WHERE TaskNum=""" & x & """)"
DoCmd.RunSQL sqls
'This works - "VALUES ('" & strCompany & "', 'cat')"
Exit_Form_Close:
Exit Sub
Err_Form_Close:
MsgBox Err.Description
Resume Exit_Form_Close
End Sub