Form Read-Only Problem

ted.martin

Registered User.
Local time
Today, 14:09
Joined
Sep 24, 2004
Messages
743
I have a form that as part of the OnLoad event, looks up some values. (Access 2007)

txtDEVctd.Value = RoundCurr(Nz(DSum("[DEVcost]", "Q-DEVcost", "VORef = " & VarNo.Value), 0), 2)
txtDOVctd.Value = RoundCurr(Nz(DSum("[DOVcost]", "Q-DOVcost", "VORef = " & VarNo.Value), 0), 2)

txtDEVctd.Value and txtDOVctd.Value are UNBOUND

Despite trying everyway possible to open this form in Read-Only, it stubbornly remains in Edit mode because (I have discovered through line by line testing), the txtVOctd.Value text control in the Load code is BOUND when the next line runs.

txtVOctd.Value = RoundCurr(txtDOVctd.Value + txtDEVctd.Value, 2)

Now if I make txtVOctd UNBOUND and instead use the piece of SQL shown below, the form will open Read Only.

DoCmd.SetWarnings False
DoCmd.RunSQL ("UPDATE [Variation Register] SET VOCosttoDATE = " & txtVOctd.Value & " WHERE VARNo = " & VarNo.Value)
DoCmd.SetWarnings True


SO ... my only question is WHY does having txtVOctd as a BOUND control prevent the form from Opening Read only when asked to do so?

I am as ever intrigued. Many thanks
 
I don't completely understand ted.

Perhaps you can throw us a sample db?
 
As requested.

At the moment the Form is set to AllowEdits = No.

The troublesome field is the red one.

Just look at the last part of the Load code. If you open the form now it will not be in ReadOnly. - try changing the Tonnage figure as that is not locked.

Then make the red box unbound and reopen and it will be read only.

Have fun and thanks
 

Attachments

You have stated the obvious. You cannot set a value on a bound field and have the form be read only so Access interprets you wanting to make the change because you said you did in the code, so it overrides the read only part. If you want to set the text box to a certain value but be read only I believe you will likely need to use an unbound text box which you can display in place of the normally bound one. You can set it to display and hide the bound one.
 
Thanks Bob - my workaround with the SQL works fine but I appreciate your comments. Now you mention it, it is of course obvious!
 

Users who are viewing this thread

Back
Top Bottom