Locking Cells

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to lock a particular (individual) cell in a subform in access.
I tried putting the following code under the fields on_enter event,
but this locks the field for every record:

If Me.UnitsOrdered <= 0 Then

MsgBox "Cannot edit - no units ordered!"
Me.UnitsReceived.Locked = True

End If

I have another proc that access the recordset of the subform to perform
other checks, but I cant figure out how to lock the individual field for a
particular record,

Do Until rs.EOF
tally = rs("UnitsReceived") + rs("UnitsUsed") + rs("UnitsDamaged")


If tally < rs("UnitsOrdered") Then
MsgBox "Incorrect Ammounts - Do Not Match Units Ordered!"
MsgBox rs("ProductName")
GoTo lastline

End If

If tally > rs("UnitsOrdered") Then
MsgBox "Incorrect Ammounts - Do Not Match Units Ordered!"
MsgBox rs("ProductID")
GoTo lastline

End If


rs.MoveNext
Loop

Thank you for any help offered!
 
I have now added an else statement that re-checks the value and unlocks as
such:

If Me.UnitsOrdered <= 0 Then
MsgBox "Cannot edit - no units ordered!"
Me.UnitsReceived.Locked = True
Else
Me.UnitsReceived.Locked = False
End If

--its a little messy, but works!
 
Nothing messy about this code... pretty standard way to do what you want!
Good work.
 
You're probably looking for a CONDITIONAL FORMATTING solution. Right
click on the UnitsReceived control and select CONDITIONAL FORMATTING.
Then select the [EXPRESSION] option. At that point you'll have to put in
the fully qualified expression to evaluate. Which would be something to
the effect of

[Forms]![myFormName]![mySubformName].form![unitsOrdered] <=0

I have never been able to get the Me. syntax to work with CF personally.

And BTW, select the button in the CF window to ENABLE/DISABLE the control.
 
Thank you both,
kenny

David C. Holley said:
You're probably looking for a CONDITIONAL FORMATTING solution. Right
click on the UnitsReceived control and select CONDITIONAL FORMATTING.
Then select the [EXPRESSION] option. At that point you'll have to put in
the fully qualified expression to evaluate. Which would be something to
the effect of

[Forms]![myFormName]![mySubformName].form![unitsOrdered] <=0

I have never been able to get the Me. syntax to work with CF personally.

And BTW, select the button in the CF window to ENABLE/DISABLE the control.
I want to lock a particular (individual) cell in a subform in access.
I tried putting the following code under the fields on_enter event,
but this locks the field for every record:

If Me.UnitsOrdered <= 0 Then

MsgBox "Cannot edit - no units ordered!"
Me.UnitsReceived.Locked = True

End If

I have another proc that access the recordset of the subform to perform
other checks, but I cant figure out how to lock the individual field for a
particular record,

Do Until rs.EOF
tally = rs("UnitsReceived") + rs("UnitsUsed") + rs("UnitsDamaged")


If tally < rs("UnitsOrdered") Then
MsgBox "Incorrect Ammounts - Do Not Match Units Ordered!"
MsgBox rs("ProductName")
GoTo lastline

End If

If tally > rs("UnitsOrdered") Then
MsgBox "Incorrect Ammounts - Do Not Match Units Ordered!"
MsgBox rs("ProductID")
GoTo lastline

End If


rs.MoveNext
Loop

Thank you for any help offered!
 
Back
Top