Glenna,
The code I provided would go in the two places that I suggested. Both of
these places are in the VBA code area of your form and the control that is
linked to the field.
You never try to do something like this in the actual table and/or field.
With your form open in design mode, first click to selecte the text box or
whatever the control is that you are wanting to preven users from changing
after the value has been entered. Then with that contol selected, right
click and select the Properties option to display the Properties dialog box.
Click on the Event tab. Locate the "After Update" event. Double click in
that row immediately to the right of the After Update. This will place the
following in this row: "[Event Procedure]" the button with the three dots
located at the far right end of this same row. This will display the VBA
Code window.
In the VBA Code Window you will see a couple of lines like the following
except with the actual name of your control:
Private Sub NameOfYourControl_AfterUpdate()
End Sub
Inside these two lines add the following lines of code:
Dim vbResponse
vbResponse = MsgBox("Is the entry you made the correct value?", vbQuestion +
vbYesNo + vbDefaultButton1)
If vbResponse = vbYes Then
Me.txtColor.Locked = True
Else
With Me.txtColor
.Value = Null
.SetFocus
End With
End If
Next, locate the two combo boxes at the top of the VBA code window. Click
the down arrow at the right end of the combo box on the left and select the
"Form" option from the list. From the combo box on the right, select the
"Current" option. Your cursor should be now located in an area that will look
like the following:
Private Sub Form_Current()
End Sub
Inside these two lines, please place the following code:
If Not IsNull(Me.NameOfYourControl) Then
Me.NameOfYourControl.Locked = True
Else
Me.NameOfYourControl.Locked = False
End If
In the code above you will need to change the "NameOfYourControl" to the
actual name of your control on your form.
After making these changes, save your form and give it a try. When you come
to any record where there is not a value in the field, you will be able to
provide a value. When you have provided a value and pressed the Tab or Enter
keys, you will be prompted to answer an "Yes" or "No" question as to whether
or not the value you provided is the correct value. When you come to any any
record where a value is already in the field, the control will be locked and
you will not be able to make any changes to the value.
You may find that in some cases users may still need some way to over ride
the locked condition. This would require tha you provied perhaps some kind
of special key combination or something that would still allow changes to be
made.
Good luck with your project.
--
HTH
Mr B
askdoctoraccess dot com
Glenna said:
How would I create the message box? I tried this on the field itself vs. the
form is that were you intended I do this formula?
:
Glenna,
Try using code in the AfterUpdate event:
If not isnull(Me.NameOfYourTextBox) then
Me.NameOfYourTextBox.Locked = true
End If
You may want to use a Msgbox to ask the user is the value entered is correct
before you lock the field from further editing. (Just a thought)
--
HTH
Mr B
askdoctoraccess dot com
:
I haev a form that currently allows you to enter new records and edit
existing records. My key field is based on a number entered by the user from
another system. Once the number is entered I do not want the user to be able
to type over that number but still be aloud to add a new record. I tried the
AllowAdditions and AllowEdits in the properties but if I set them to Yes
AllowAdditions and No AllowEdits then nothing can be changed. I want them to
be able to edit everything but the one field containing the number. Ideas?