ReadOnly - NOT

S

Stu

PROBLEM: I open a form as ReadOnly but I can change any data regardless.
Further info below.

From a button click on Form A, I open a pop-up Form B as follows:
DoCmd.OpenForm "frmWeb_info", , , , acFormReadOnly, , Me.ItemID

My Form B Load Event is as follows, there is no Current Event code:
Private Sub form_load()
Me.Filter = "itemID = " & Me.OpenArgs
Me.FilterOn = True
'''MsgBox Me.DataEntry '''Me.Data Entry will display False
Me.LeadURL = "https://www.somewhere.com"
Me.PartURL = "https://www.somewhere.com"
End Sub

Why doesn't Form B open as Read Only? Please prompt if more info is needed.

Thanks.
 
D

Dirk Goldgar

Stu said:
PROBLEM: I open a form as ReadOnly but I can change any data regardless.
Further info below.

From a button click on Form A, I open a pop-up Form B as follows:
DoCmd.OpenForm "frmWeb_info", , , , acFormReadOnly, , Me.ItemID

My Form B Load Event is as follows, there is no Current Event code:
Private Sub form_load()
Me.Filter = "itemID = " & Me.OpenArgs
Me.FilterOn = True
'''MsgBox Me.DataEntry '''Me.Data Entry will display False
Me.LeadURL = "https://www.somewhere.com"
Me.PartURL = "https://www.somewhere.com"
End Sub

Why doesn't Form B open as Read Only? Please prompt if more info is
needed.


What version of Access? I can't reproduce this using Access 2003. Do you
have any code in the form's Open event, maybe, that sets the RecordSource?
 
S

Stu

The Load event is the only code I have on the Form object. The only other
code is on textbox afterupdate events and button click events. Access
version 2003. I've used the acReadOnly constant several other times but have
not ever seen this behaviour.

Thanks for your response/follow-up.
 
D

Dirk Goldgar

Stu said:
The Load event is the only code I have on the Form object. The only other
code is on textbox afterupdate events and button click events. Access
version 2003. I've used the acReadOnly constant several other times but
have
not ever seen this behaviour.


Could it be that the form is already open when the OpenForm method is
called? Maybe hidden?
 
D

Dale Fye

OpenArgs returns a string, could that be part of the problem?

Rather than use the OpenArgs parameter, why are you not using the
WhereCondition of the OpenForm method:

docmd.OpenForm "frmWeb_info",, , "[ItemID] = " & me.ItemID,acFormReadOnly

What are the values for the AllowAdditions, AllowEdits, and DataEntry
properties of FormB?
 
L

Linq Adams via AccessMonster.com

The problem lies in your lines:

When you assign values thru code, the current record then becomes editable,
even when the form is opened in ReadOnly mode. All you have to do to correct
this is to move to another record, then back, and the ReadOnly mode will be
re-instated. So something like

Me.LeadURL = "https://www.somewhere.com"
Me.PartURL = "https://www.somewhere.com"
DoCmd.GoToRecord , , acNext
DoCmd.GoToRecord , , acPrevious

should do it, assuming that the first record isn't the only record in the
recordset.
 
D

Dirk Goldgar

Linq Adams via AccessMonster.com said:
The problem lies in your lines:

When you assign values thru code, the current record then becomes
editable,
even when the form is opened in ReadOnly mode.

Great spot, Linq! I forgot all about that, and didn't even try assigning to
a form field.
All you have to do to correct
this is to move to another record, then back, and the ReadOnly mode will
be
re-instated. So something like

Me.LeadURL = "https://www.somewhere.com"
Me.PartURL = "https://www.somewhere.com"
DoCmd.GoToRecord , , acNext
DoCmd.GoToRecord , , acPrevious

should do it, assuming that the first record isn't the only record in the
recordset.

Another way would be to explicitly save the record, as for example by
executing:

Me.Dirty = False

On the other hand, are you really wanting to save the form's record? Stu,
what is the purpose of your code, that you are opening the form read-only
but modifying bound controls on the form?
 

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