Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

lock field or allow entry only once?

Status
Not open for further replies.

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
 
Try adding this at the end of your lost focus code:

NumRecords.Enabled = False
 
Thank you mgolla
I tried adding NumRecords.Enabled = False at the send of the sub, but got the following message "can't disable a control while it has the focus"



JLopez
Lopez31@ATC-Enviro.com
Environmental Services @ Your Service
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top