i believe it was this article from Allen Browne that i first found and started using @@identity. https://bytes.com/topic/access/answe...ng-insert-into
as for my where condition, any more thoughts? i did find something that works but i don't think i like it just because it looks messy. i moved my sqlrs2 SQL and set rs2 inside the first loop just under the execute command along with declaring a variable that pulls the circularid from rs1 and then use that variable inside a where clause for my sqlrs2 SQL. not sure if this is making sence so i'll add the code again.
Code:
Private Function circular1()
Dim db As DAO.Database
Dim rs1 As DAO.Recordset '''circular table'''
Dim rs2 As DAO.Recordset '''circular craft table'''
Dim sqlrs1 As String '''circular sql'''
Dim sqlrs2 As String '''circular craft sql'''
Dim x As Integer
Dim n As Date
Dim c As Integer
sqlrs1 = "SELECT * FROM circularT" '''get circular table'''
Set db = CurrentDb
Set rs1 = db.OpenRecordset(sqlrs1)
With rs1 '''loop thru circulart'''
If Not .BOF And Not .EOF Then '''check to see if on a record'''
.MoveFirst
Do Until .EOF
If (!DueDate - Date) <= 0 Then '''check due dates that are due today or past'''
'''insert main job into record'''
CurrentDb.Execute ("INSERT INTO workqueT(circularid, locid, deptid, systemid, assetid, componentid,workid,summary,detail,statusid) " & _
"VALUES(" & !circularid & "," & !LocID & "," & !DeptID & "," & !SystemID & "," & !AssetID & "," & _
!ComponentID & "," & !WorkID & ",""" & !Summary & """,""" & !detail & """," & 1 & ") ")
c = !circularid
n = !DueDate + 5 '''set new due date'''
CurrentDb.Execute ("UPDATE circularT SET duedate=#" & Format(n, "mm/dd/yyyy") & "# WHERE circularid=" & !circularid & " ")
x = CurrentDb.OpenRecordset("select @@identity")(0) '''get unique ID'''
sqlrs2 = "SELECT * FROM circularcraftT WHERE circularid=" & c '''get circular craft table'''"
Set rs2 = db.OpenRecordset(sqlrs2)
With rs2 '''loop thru circularcraftt'''
If Not .BOF And Not .EOF Then
.MoveFirst
Do Until .EOF
'''insert the crafts for the main jobs'''
CurrentDb.Execute ("INSERT INTO WorkquecraftT(workqueID,craftid,hours,craftnotes,statusid) " & _
"VALUES (" & x & "," & !CraftID & ",'" & !Hours & "',""" & !CraftNotes & """,'" & 5 & "') ")
'''WHERE CircularID=" & c & "
.MoveNext
Loop
.Close
End If
End With
End If
.MoveNext
Loop
.Close
End If
End With
Set rs2 = Nothing
Set rs1 = Nothing
Set db = Nothing
End Function
so far it works but not sure if its be best way. thanks