jlnewbie
Technical User
- Aug 9, 2000
- 69
I have field in a datasheet form that when lost focus, enters N number of records in another table. Below is my code. It seems to work great until someone tabs over that existing entry again,giving me additional records I don’t need. How can I lock or set the code to allow entry only once? I’m not too well versed in coding. Thank You
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("tblSample_Analysis_2004", dbOpenDynaset)
For indx1 = 1 To indx
RSMT.AddNew
RSMT![Batch] = Nkey
RSMT.Update
Next indx1
RSMT.Close
MyAddFunction = "Aokay"
End Function
JLopez
Lopez31@ATC-Enviro.com
Environmental Services @ Your Service
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("tblSample_Analysis_2004", dbOpenDynaset)
For indx1 = 1 To indx
RSMT.AddNew
RSMT![Batch] = Nkey
RSMT.Update
Next indx1
RSMT.Close
MyAddFunction = "Aokay"
End Function
JLopez
Lopez31@ATC-Enviro.com
Environmental Services @ Your Service