Graceful Way To Conditionally Allow Editing A Field?

P

PeteCresswell

Got a field on a multi-row subform that should only be allowed tb
changed if certain conditions are met.

I don't know any way of making it editable/non-editable on-the-fly, so
I'm doing this - which seems kind of kludgey to me, although I guess I
could mitigate things slightly by using Conditional Formatting to vary
the backcolor of the field so the user sees whether it is going tb
allowed an edit or not...

Is there a better way?
====================================================
Private Sub txtRate_BeforeUpdate(Cancel As Integer)
DebugStackPush Me.Name & ": txtRate_BeforeUpdate"
On Error GoTo txtRate_BeforeUpdate_err

' PURPOSE: To to allow editing only buy items where Settlement=Issue
date

With Me
If Not ((.txtTradeTypeID = gTradeTypeID_Buy) And (DateDiff
("d", .txtSettlementDate, .Parent!subSecurity.Form!txtIssueDate) = 0))
Then
Cancel = True
MsgBox "You may only change Buy Rate on buys and where
settlement and issue date are equal." & vbCrLf & vbCrLf & "Press the
Esc key to restore old value and exit the field.", vbExclamation,
"Change Not Allowed"
End If
End With

txtRate_BeforeUpdate_xit:
DebugStackPop
On Error Resume Next
Exit Sub

txtRate_BeforeUpdate_err:
BugAlert True, ""
Resume txtRate_BeforeUpdate_xit
End Sub
====================================================
 
D

Douglas J. Steele

If you put code in the form's Current event, you can lock the controls when
the current row doesn't meet the conditions (and unlock the controls when
the current row does meet the conditions).

Yes, it'll lock the controls for every row on the form, but since you can
only work with one row at a time, it shouldn't matter: when you move to
another (valid) row, the controls will unlock.
 
R

Ron2006

You can also use conditional formating to "disable" the field. This
will work row by row independently even in datasheet view.
This will grey the field out when it is disabled.

Ron
 
A

a a r o n . k e m p f

Uh, SQL Server permissions would probably do what you're trying to do.

(allow some people to edit fields, and lock it for others)
if you care enough to build a database-- use a database with a
future-- like SQL Server for example

Jet is too buggy to use in the real world, sorry, but you got suckered
into a crap database platform!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top