Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detect if a form is ReadOnly? 2

Status
Not open for further replies.

maetrix

Technical User
Jul 27, 2002
14
CA
Is there a way to detect if acFormReadOnly or other such parameters were used when opening a form?
Novice Programmer;
Expert Hack


sapere aude: Dare to be wise
 
Here is one way to do it.

If Me.DataEntry = True Then
The form is Editable
Else
The form is Read Only
End If

To test this out, create a new form, set the DataEntry property to yes, use this condition with a message box.


Dim res as String
If Me.DataEntry = True Then
res = MsgBox("This Form is Editable", vbOKOnly, "fyi")
Else
res = MsgBox("This Form is Read Only", vbOKOnly, "fyi")
End If


Then use your openform command with the read only argument
See Below

DoCmd.OpenForm "form1", acNormal, , , acFormReadOnly


Then see which message you get.
You should get "This Form is Read Only"
That's the message I get.

David I'm Your Huckleberry!
 
I have to (slightly) disagree...

The appropriate property is AllowEdits, so:

If AllowEdits Then
MsgBox "Fully Editable"
Elseif DataEntry And NewRecord Then
MsgBox "Editable now: new record"
Else
MsgBox "Not Editable"
End If

If it's a data entry form with AllowEdits = False, you can edit only[b/] the new record. All saved records that may still be on the screen are read only...

Now I have a (stupid) question: why did you use MsgBox() function instead of MsgBox statement?


Regards,
Dan
[pipe]

 
The MsgBox thing is just a preference of mine.

I guess the real test is not what you can do in the form, but what the properties of the form are when it is opened using the acFormReadOnly property.

DoCmd.OpenForm "form1", acNormal, , , acFormReadOnly

Even if the Form's default DataEntry is set to Yes (True),
the form will be opened with the above command and the DataEntry property will be set to No (False), presumably because You cannot do Data Entry on a Form that is Read Only

Unless I'm missing something, that should do the trick. I'm Your Huckleberry!
 
You just have to figure out what properties you want to test for and determine how to test for them.

Whether a form was opened in Read Only, Normal, Add New, Edit, ect.

David I'm Your Huckleberry!
 
Than you all very much for you help.. checking for AllowEdits worked perfectly for my needs.

--Toby-- Novice Programmer;
Expert Hack


sapere aude: Dare to be wise
 
Yes...but re-reading your original post, I can say david was right...you asked if "acFormReadOnly or other such parameters were used when opening a form"
I gave you a solution to check if the form accepts edits at the moment of checking...

So David, get one from me!


Regards,

Dan

[pipe]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top