Hi, I have some code (see step 1 below) that updates a set of contact records (tblContact) and adds a value for the field projectID (FK). The next step is an append query to insert records into an intersection table called tblSegment for each record that was just updated in tblContact. The problem is that the 2nd step fails ... for some reason I have to run the code a 2nd time for the append query to "see" the records that were updated by step 1. Is there a way to "commit" the updates so that step 2 will succeed? Thanks for any help with this problem.
Here is the code:
strProjectID = Me!projectID
strQryName = Me!proj_query
strText = "Step 1: Updating Contact records"
MsgBox (strText)
' promote contacts to research participants
' update tblContact with project id and active status = y using stored select query named in tblProject
Dim myUpdQuery As QueryDef
' Build SQL statement
strSQL = "UPDATE " & strQryName & " SET " & "cont_projectID = '" & strProjectID & "', " & "cont_active_status = 'Y';"
Set myUpdQuery = myDB.CreateQueryDef("", strSQL) ' create temp update query
' Run temporary QueryDef
myUpdQuery.Execute
myUpdQuery.Close
' ***************** Begin Step 2 *******************
strText = "Step 2: Appending Segment records"
MsgBox (strText)
' populate tblSegment records (intersection table) for all contacts participating in this project
' this table facilitates the many to many relationship between projects and contacts
Dim myAppendQuery As QueryDef
' build SQL statement for append query
strSQL = "INSERT INTO tblSegment ( seg_projectID, seg_contactID ) " & _
"SELECT tblContact.cont_projectID, tblContact.contactID " & _
"FROM tblContact WHERE (((tblContact.cont_projectID)='" & strProjectID & "'));"
Set myAppendQuery = myDB.CreateQueryDef("", strSQL) ' create temp append query
' run temporary QueryDef
myAppendQuery.Execute
myAppendQuery.Close
Here is the code:
strProjectID = Me!projectID
strQryName = Me!proj_query
strText = "Step 1: Updating Contact records"
MsgBox (strText)
' promote contacts to research participants
' update tblContact with project id and active status = y using stored select query named in tblProject
Dim myUpdQuery As QueryDef
' Build SQL statement
strSQL = "UPDATE " & strQryName & " SET " & "cont_projectID = '" & strProjectID & "', " & "cont_active_status = 'Y';"
Set myUpdQuery = myDB.CreateQueryDef("", strSQL) ' create temp update query
' Run temporary QueryDef
myUpdQuery.Execute
myUpdQuery.Close
' ***************** Begin Step 2 *******************
strText = "Step 2: Appending Segment records"
MsgBox (strText)
' populate tblSegment records (intersection table) for all contacts participating in this project
' this table facilitates the many to many relationship between projects and contacts
Dim myAppendQuery As QueryDef
' build SQL statement for append query
strSQL = "INSERT INTO tblSegment ( seg_projectID, seg_contactID ) " & _
"SELECT tblContact.cont_projectID, tblContact.contactID " & _
"FROM tblContact WHERE (((tblContact.cont_projectID)='" & strProjectID & "'));"
Set myAppendQuery = myDB.CreateQueryDef("", strSQL) ' create temp append query
' run temporary QueryDef
myAppendQuery.Execute
myAppendQuery.Close