Kayleigh
Member
- Local time
- Today, 16:28
- Joined
- Sep 24, 2020
- Messages
- 709
Working on an add record function which moves records from list available and creates new record in related table with item and logID. The trouble is that the primary key of related table is an autonumber so not sure how to add field in DAO. Have looked at some sample code but couldn't find clear-cut answer...
Code so far:
Table structure:
tblIncidentLog (fldIncidentLogID as PK) > tblIncidentLogDetails (fldIncidentLogDetailsID as PK; also contains fldIncidentLogID and fldStudentID)
Code so far:
Code:
Private Sub cmdUpdateStudents_Click()
Dim X As Integer
Dim i As Variant
Dim DBS As DAO.Database
Dim rst As DAO.Recordset
Dim td As DAO.TableDef
Set DBS = CurrentDb
Set td = DBS.TableDefs!tblIncidentLogDetails
Set rst = td.OpenRecordset
For Each i In Me.lstPossStudents.ItemsSelected
rst.AddNew
rst!fldStudentID = Me.lstPossStudents.ItemData(i)
rst!fldIncidentLogID = Me.fldIncidentLogID
Debug.Print Me.lstPossStudents.ItemData(i)
On Error Resume Next
rst.Update
Next i
rst.Close
Set rst = Nothing
Set td = Nothing
Me.Refresh
Exit Sub
End Sub
Table structure:
tblIncidentLog (fldIncidentLogID as PK) > tblIncidentLogDetails (fldIncidentLogDetailsID as PK; also contains fldIncidentLogID and fldStudentID)