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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable a field on a form after data entered in that field

Status
Not open for further replies.

torf66

Programmer
Jun 10, 2003
43
US
I have a form MyForm that has a field on the form called
numAdmitNumber. I want it so that the user can only enter into this field when adding a new record to the database.
When they first come into the MyForm it comes to the first record in the database. I want the field numAdmitNumber to be visible but I do not want them to be able to update that field. They can update any of the other fields on the form but just not that one once the initial value is entered. This field numAdmitNumber is the key for the table of information being displayed. How can this be done?


Also is there a way when you are setting up a query in the criteria field to enter a wild card to a field defined as a number. For example I have a field called numAdmitNumber. When I run the query I want to be able to allow the user to enter any number into the entry and find the value. For example I enter a 1 then it finds any records that start with a 1 so I would fine admit numbers 12, 123 or 1234. If I enter 123 then I find the records 123, 1234.

Thanks,
Todd ttorfin@dakcl.com
 
2. I put this code in below is that correct?

Private Sub Form_Current()

If (IsNull(numAdmitNumber)) Then
numAdmitNumber.BackColor = 16777215
numAdmitNumber.ForeColor = 0
Else
numAdmitNumber.BackColor = 12632256
numAdmitNumber.ForeColor = 0
End If

3. I am struggling with. I put this in the Got Focus and
the grey color goes away when I tab to another field on the form.

Private Sub numAdmitNumber_GotFocus()
numAdmitNumber.Locked = Not NewRecord
If (IsNull(numAdmitNumber)) Then
numAdmitNumber.BackColor = 16777215
numAdmitNumber.ForeColor = 0
Else
numAdmitNumber.BackColor = 12632256
numAdmitNumber.ForeColor = 0
End If
 
An issue with this code below is it works great when you try to enter something into the field and the message does not display when you tab or hit enter out of the field, but when I add a new record and then say for example I enter 123 but the number should have been 321 then I cannot go back and correct the entry.

Private Sub numAdmitNumber_KeyDown(KeyCode As Integer, Shift As Integer)
If (Not IsNull(numAdmitNumber)) And (KeyCode >= 32)) Then
MsgBox "No changes possible"
End If
End Sub
 
Private Sub Form_Current()
numAdmitNumber.Locked = Not (IsNull(numAdmitNumber) Or NewRecord)
End Sub

Private Sub numAdmitNumber_KeyDown(KeyCode As Integer, Shift As Integer)
If numAdmitNumber.Locked Then
MsgBox "No changes possible"
End If
End Sub

Code dissector: In your GotFocus code, the ForeColor is set to 0 (black) in all cases. Set it in the properties of the control and get rid of the lines in code. Keep it short and simple...



[pipe]
Daniel Vlas
Systems Consultant

 
Issues I still have:
The message 'No Changes Possible' still shows when I tab to the next field. If I use the code you suggested
below for the KeyDown then when I enter a new record and enter 123 in numAdmitNumber then I notice in that record when I am adding the numAdmitNumber should be 321 when I try to enter 321 the message "No Changes Possible" shows and I cannot change the numAdmitNumber. All this time I am in the Add Record Mode. This logic works great when I try to change something in an existing record for the numAdmitNumber and it allows me to tab or enter off the field without the message displaying. If I could only get it to allow me to enter over a mistake in the numAdmitNumber then I would be all set.

Private Sub numAdmitNumber_KeyDown(KeyCode As Integer, Shift As Integer)
If (Not IsNull(numAdmitNumber)) And (KeyCode >= 32)) Then
MsgBox "No changes possible"
End If
End Sub

This is what I have in the Got Focus and Key Down event right now:

Private Sub numAdmitNumber_GotFocus()
numAdmitNumber.Locked = Not NewRecord
End Sub

Private Sub numAdmitNumber_KeyDown(KeyCode As Integer, Shift As Integer)
If (Not IsNull(numAdmitNumber)) And (KeyCode >= 32)) Then
MsgBox "No changes possible"
End If
End Sub



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top