Yes, it works by adding:
Code:
If Me.Dirty Then Me.Dirty = False
Thank you so much. Now I'll have to read about Me.Dirty to find out what it does, and why. Then, I'll tackle the problem where if a user changes the value in the textbox then new duplicate records won't be added. If I can't figure it out, then I'll start a new thread. But for now, this thread is SOLVED!
Working code:
Code:
Private Sub NoOfSamples_AfterUpdate()
'To autopopulate the [SampleNo] field in the subform with
'sequential numbers up to the value in the [NoOfSamples] field in the main form.
Dim intSmplNo As Integer
Dim strSQL2 As String
intSmplNo = Forms!frmSampleLogIn01!NoOfSamples.Value
If Me.Dirty Then Me.Dirty = False
For i = 1 To intSmplNo
strSQL2 = "INSERT INTO tblMycoData (AccessionNo, SampleNo) Values(" & Forms!frmSampleLogIn01!AccessionNo & ", " & i & ")"
CurrentDb.Execute strSQL2, dbFailOnError
Next i
Me.subMycoData.Form.Requery
End Sub