HI All,
First, let me say that it is good to be back. One programmer, 4 years ago was extremely helpful and I had not posted anything since then. Thank you in advance.
I have the following two addnew record function that will add x number of records to table2(child) based on table1(Primary).
I enter 3 in [NumberInspections] in main form and three records get added on requery to the subform of table2
Number 2, Works real well in one database but Number 1 does not in the other. I've have gotten two errors with the second set of functions that I can't figure out what and I don't know enough coding as self taught myself and still a newbie. "Compile ERROR - User defined type not defined" and another error says that it can't run because it would generate duplicate records in table"
What I'm doing wrong?? Please help
Number 1
Private Sub NumberInspections_LostFocus()
Dim indx As Integer, Nkey As Integer, returnOkay As String
indx = Me.[NumberInspections]
Nkey = Me.MaterialRecordID
returnOkay = MyAddFunction(indx, Nkey)
End Sub
Function MyAddFunction(indx As Integer, Nkey As Integer) As String
Dim RSMT As DAO.Recordset, indx1 As Integer
Set RSMT = CurrentDb.openrecordset("tblInspectionFindings_Periodic", dbOpenDynaset, dbSeeChanges)
For indx1 = 1 To indx
RSMT.AddNew
RSMT![MaterialRecordID] = Nkey
RSMT.Update
Next indx1
RSMT.Close
MyAddFunction = "Aokay"
End Function
Number2
Private Sub NumRecords_LostFocus()
Dim indx As Integer, Nkey As Integer, returnOkay As String
indx = Me.[NumRecords]
Nkey = Me.Batch
returnOkay = MyAddFunction(indx, Nkey)
End Sub
Function MyAddFunction(indx As Integer, Nkey As Integer) As String
Dim RSMT As DAO.Recordset, indx1 As Integer
Set RSMT = CurrentDb.OpenRecordset("tblSamplePLM", dbOpenDynaset, dbSeeChanges)
For indx1 = 1 To indx
RSMT.AddNew
RSMT![Batch] = Nkey
RSMT.Update
Next indx1
RSMT.Close
MyAddFunction = "Aokay"
End Function
First, let me say that it is good to be back. One programmer, 4 years ago was extremely helpful and I had not posted anything since then. Thank you in advance.
I have the following two addnew record function that will add x number of records to table2(child) based on table1(Primary).
I enter 3 in [NumberInspections] in main form and three records get added on requery to the subform of table2
Number 2, Works real well in one database but Number 1 does not in the other. I've have gotten two errors with the second set of functions that I can't figure out what and I don't know enough coding as self taught myself and still a newbie. "Compile ERROR - User defined type not defined" and another error says that it can't run because it would generate duplicate records in table"
What I'm doing wrong?? Please help
Number 1
Private Sub NumberInspections_LostFocus()
Dim indx As Integer, Nkey As Integer, returnOkay As String
indx = Me.[NumberInspections]
Nkey = Me.MaterialRecordID
returnOkay = MyAddFunction(indx, Nkey)
End Sub
Function MyAddFunction(indx As Integer, Nkey As Integer) As String
Dim RSMT As DAO.Recordset, indx1 As Integer
Set RSMT = CurrentDb.openrecordset("tblInspectionFindings_Periodic", dbOpenDynaset, dbSeeChanges)
For indx1 = 1 To indx
RSMT.AddNew
RSMT![MaterialRecordID] = Nkey
RSMT.Update
Next indx1
RSMT.Close
MyAddFunction = "Aokay"
End Function
Number2
Private Sub NumRecords_LostFocus()
Dim indx As Integer, Nkey As Integer, returnOkay As String
indx = Me.[NumRecords]
Nkey = Me.Batch
returnOkay = MyAddFunction(indx, Nkey)
End Sub
Function MyAddFunction(indx As Integer, Nkey As Integer) As String
Dim RSMT As DAO.Recordset, indx1 As Integer
Set RSMT = CurrentDb.OpenRecordset("tblSamplePLM", dbOpenDynaset, dbSeeChanges)
For indx1 = 1 To indx
RSMT.AddNew
RSMT![Batch] = Nkey
RSMT.Update
Next indx1
RSMT.Close
MyAddFunction = "Aokay"
End Function