2021年1月16日星期六

Microsoft Access VBA - Locking a field when value in the field is not null

I have fallen into a rut building a quote creation tool. I have a combo box that selects an item for the quote and will populate all of the fields for that line. In this case, I want the [Cost] field to be locked, preventing any changes. However, there are times when a user must type an item for the quote that is not in the combo box; therefore, all of the fields on that line will be null and must be typed manually.

I am trying to write a VBA event where [Cost] is locked when [Cost] is not null, preventing any change; and where [Cost] is not locked when [Cost] is Null, allowing editing.

Private Sub Form_Current()  If IsNull(Me.Cost) = True Then      Me.Cost.Locked = False  Else      Me.Cost.Locked = True  End If  End Sub  

Design view of subform

Form view of complete form

  • The top line is in the combo box and the entire line is populated; Here I want cost to be locked
  • The second line is not in the combo and the line must be manually entered; Here I want lock to be disabled
https://stackoverflow.com/questions/65727612/microsoft-access-vba-locking-a-field-when-value-in-the-field-is-not-null January 15, 2021 at 06:08AM

没有评论:

发表评论