Test form for read only

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

Guest

Hi,

How do I determine if a form has been opened in read ony mode.

ie. If frmExample "Is opened as read only" then
do whatever
Else
do something else
End if

TIA,
Duncan
 
Not sure how you define "read-only", but you could test the AllowEdits
property of the form:
If Forms("frmExample").AllowEdits Then
MsgBox "read only"
Else
MsgBox "normal
End If

That should work if the form was opened this way:
DoCmd.OpenForm "frmExample",,,,acFormReadOnly

However, there are many other reasons a form might be read-only, such as:
- It is based on a query that is not updatable.
- The user does not have write privileges.
- The database was opened read-only, or the drive or media is read-only.
 
Allen (or anyone else who can help),

I've tried to use the method you outline below with no success.

I have a form with a button to toggle back and forth between "Edit" mode and
"Read-Only" mode (the button calls a macro that sets the AllowEdits,
AllowDeletions and AllowAdditions properties). The button works great, but
now I have some code that I only want to fire if the form is in "Edit" mode.

I tried using "If Forms("frmExample").AllowEdits Then" but it aways
evaluates to True and executes the statements after Then. I also tried "If
Forms("frmExample").AllowEdits = True Then" and got the same results. I then
tried printing to the Immediate window (Debug.Print Forms![Purchase
Order]![Ship History subform].AllowEdits) and got a carriage return.
Thinking a Null might be the problem I used the Nz function and got the same
result (a carriage return).

I've tried every combination of the above I could think of and tested each
for both AllowEdits = True and AllowEdits = False. What am I doing wrong???
I actually have a workaround for this situation, but I'd like to know what's
going wrong; there are other times when I'd like to be able to determine
whether the form is in "Edit" mode or not.

Thaks for all your help.

Kari
 
Kari:

Is the code that you are using to check this on the form in question? If
so, don't use the fully qualified name, just use ME.

If Me.AllowEdits = True Then

etc.


Kari said:
Allen (or anyone else who can help),

I've tried to use the method you outline below with no success.

I have a form with a button to toggle back and forth between "Edit" mode
and
"Read-Only" mode (the button calls a macro that sets the AllowEdits,
AllowDeletions and AllowAdditions properties). The button works great,
but
now I have some code that I only want to fire if the form is in "Edit"
mode.

I tried using "If Forms("frmExample").AllowEdits Then" but it aways
evaluates to True and executes the statements after Then. I also tried
"If
Forms("frmExample").AllowEdits = True Then" and got the same results. I
then
tried printing to the Immediate window (Debug.Print Forms![Purchase
Order]![Ship History subform].AllowEdits) and got a carriage return.
Thinking a Null might be the problem I used the Nz function and got the
same
result (a carriage return).

I've tried every combination of the above I could think of and tested each
for both AllowEdits = True and AllowEdits = False. What am I doing
wrong???
I actually have a workaround for this situation, but I'd like to know
what's
going wrong; there are other times when I'd like to be able to determine
whether the form is in "Edit" mode or not.

Thaks for all your help.

Kari

Allen Browne said:
Not sure how you define "read-only", but you could test the AllowEdits
property of the form:
If Forms("frmExample").AllowEdits Then
MsgBox "read only"
Else
MsgBox "normal
End If

That should work if the form was opened this way:
DoCmd.OpenForm "frmExample",,,,acFormReadOnly

However, there are many other reasons a form might be read-only, such as:
- It is based on a query that is not updatable.
- The user does not have write privileges.
- The database was opened read-only, or the drive or media is read-only.
 
Bob,

Thank you for your reply. The code is in a function in a module. I think
the problem is that I'm trying to determine what the AllowEdits property is
for a subform. If I look at the parent form's property I get the right
answer (details below). Is there any way to check the subform's AllowEdits
property directly?

This works:
If Forms![Purchase Order].AllowEdits = False Then

This doesn't:
If Forms![Purchase Order]![Ship History subform].AllowEdits Then

I don't hink I can use Me from a module, can I? I will check that, as well
as double checking that I was using the subform control name, not just the
form name.

Thanks for your help.

Kari



Bob Larson said:
Kari:

Is the code that you are using to check this on the form in question? If
so, don't use the fully qualified name, just use ME.

If Me.AllowEdits = True Then

etc.


Kari said:
Allen (or anyone else who can help),

I've tried to use the method you outline below with no success.

I have a form with a button to toggle back and forth between "Edit" mode
and
"Read-Only" mode (the button calls a macro that sets the AllowEdits,
AllowDeletions and AllowAdditions properties). The button works great,
but
now I have some code that I only want to fire if the form is in "Edit"
mode.

I tried using "If Forms("frmExample").AllowEdits Then" but it aways
evaluates to True and executes the statements after Then. I also tried
"If
Forms("frmExample").AllowEdits = True Then" and got the same results. I
then
tried printing to the Immediate window (Debug.Print Forms![Purchase
Order]![Ship History subform].AllowEdits) and got a carriage return.
Thinking a Null might be the problem I used the Nz function and got the
same
result (a carriage return).

I've tried every combination of the above I could think of and tested each
for both AllowEdits = True and AllowEdits = False. What am I doing
wrong???
I actually have a workaround for this situation, but I'd like to know
what's
going wrong; there are other times when I'd like to be able to determine
whether the form is in "Edit" mode or not.

Thaks for all your help.

Kari

Allen Browne said:
Not sure how you define "read-only", but you could test the AllowEdits
property of the form:
If Forms("frmExample").AllowEdits Then
MsgBox "read only"
Else
MsgBox "normal
End If

That should work if the form was opened this way:
DoCmd.OpenForm "frmExample",,,,acFormReadOnly

However, there are many other reasons a form might be read-only, such as:
- It is based on a query that is not updatable.
- The user does not have write privileges.
- The database was opened read-only, or the drive or media is read-only.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.


How do I determine if a form has been opened in read ony mode.

ie. If frmExample "Is opened as read only" then
do whatever
Else
do something else
End if

TIA,
Duncan
 
For that, make sure you know what the subform container name is (the control
that houses the subform on the main form) because it COULD be the same as
the subform, which is okay, but a lot of times it isn't and in this case you
need to refer to IT instead of the subform.

So, if your container is actually named Ship History subform then you can
use
If Forms![Purchase Order].[Ship History subform].FORM.AllowEdits Then

You have to add the .FORM. part in to tell access you want to refer to the
actual subform within the subform container.

See here for more about subforms:
http://www.btabdevelopment.com/main...rhowtoreferencesubforms/tabid/76/Default.aspx


--

Bob Larson
Access MVP
Access World Forums Administrator
Utter Access VIP
Free Access Resources at http://www.btabdevelopment.com

Kari said:
Bob,

Thank you for your reply. The code is in a function in a module. I think
the problem is that I'm trying to determine what the AllowEdits property
is
for a subform. If I look at the parent form's property I get the right
answer (details below). Is there any way to check the subform's
AllowEdits
property directly?

This works:
If Forms![Purchase Order].AllowEdits = False Then

This doesn't:
If Forms![Purchase Order]![Ship History subform].AllowEdits Then

I don't hink I can use Me from a module, can I? I will check that, as
well
as double checking that I was using the subform control name, not just the
form name.

Thanks for your help.

Kari



Bob Larson said:
Kari:

Is the code that you are using to check this on the form in question? If
so, don't use the fully qualified name, just use ME.

If Me.AllowEdits = True Then

etc.


Kari said:
Allen (or anyone else who can help),

I've tried to use the method you outline below with no success.

I have a form with a button to toggle back and forth between "Edit"
mode
and
"Read-Only" mode (the button calls a macro that sets the AllowEdits,
AllowDeletions and AllowAdditions properties). The button works great,
but
now I have some code that I only want to fire if the form is in "Edit"
mode.

I tried using "If Forms("frmExample").AllowEdits Then" but it aways
evaluates to True and executes the statements after Then. I also tried
"If
Forms("frmExample").AllowEdits = True Then" and got the same results.
I
then
tried printing to the Immediate window (Debug.Print Forms![Purchase
Order]![Ship History subform].AllowEdits) and got a carriage return.
Thinking a Null might be the problem I used the Nz function and got the
same
result (a carriage return).

I've tried every combination of the above I could think of and tested
each
for both AllowEdits = True and AllowEdits = False. What am I doing
wrong???
I actually have a workaround for this situation, but I'd like to know
what's
going wrong; there are other times when I'd like to be able to
determine
whether the form is in "Edit" mode or not.

Thaks for all your help.

Kari

:

Not sure how you define "read-only", but you could test the AllowEdits
property of the form:
If Forms("frmExample").AllowEdits Then
MsgBox "read only"
Else
MsgBox "normal
End If

That should work if the form was opened this way:
DoCmd.OpenForm "frmExample",,,,acFormReadOnly

However, there are many other reasons a form might be read-only, such
as:
- It is based on a query that is not updatable.
- The user does not have write privileges.
- The database was opened read-only, or the drive or media is
read-only.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.


How do I determine if a form has been opened in read ony mode.

ie. If frmExample "Is opened as read only" then
do whatever
Else
do something else
End if

TIA,
Duncan
 
Bob,

That worked!!! Thank you so much for all your help. The container name
was correct but I needed the .Form part.

Thank you so much for figuring this out; it has been bugging me for a long
time. Thanks for the link as well. I will go check it out as I still have
several questions concerning my subforms.

Kari

boblarson said:
For that, make sure you know what the subform container name is (the control
that houses the subform on the main form) because it COULD be the same as
the subform, which is okay, but a lot of times it isn't and in this case you
need to refer to IT instead of the subform.

So, if your container is actually named Ship History subform then you can
use
If Forms![Purchase Order].[Ship History subform].FORM.AllowEdits Then

You have to add the .FORM. part in to tell access you want to refer to the
actual subform within the subform container.

See here for more about subforms:
http://www.btabdevelopment.com/main...rhowtoreferencesubforms/tabid/76/Default.aspx


--

Bob Larson
Access MVP
Access World Forums Administrator
Utter Access VIP
Free Access Resources at http://www.btabdevelopment.com

Kari said:
Bob,

Thank you for your reply. The code is in a function in a module. I think
the problem is that I'm trying to determine what the AllowEdits property
is
for a subform. If I look at the parent form's property I get the right
answer (details below). Is there any way to check the subform's
AllowEdits
property directly?

This works:
If Forms![Purchase Order].AllowEdits = False Then

This doesn't:
If Forms![Purchase Order]![Ship History subform].AllowEdits Then

I don't hink I can use Me from a module, can I? I will check that, as
well
as double checking that I was using the subform control name, not just the
form name.

Thanks for your help.

Kari



Bob Larson said:
Kari:

Is the code that you are using to check this on the form in question? If
so, don't use the fully qualified name, just use ME.

If Me.AllowEdits = True Then

etc.


Allen (or anyone else who can help),

I've tried to use the method you outline below with no success.

I have a form with a button to toggle back and forth between "Edit"
mode
and
"Read-Only" mode (the button calls a macro that sets the AllowEdits,
AllowDeletions and AllowAdditions properties). The button works great,
but
now I have some code that I only want to fire if the form is in "Edit"
mode.

I tried using "If Forms("frmExample").AllowEdits Then" but it aways
evaluates to True and executes the statements after Then. I also tried
"If
Forms("frmExample").AllowEdits = True Then" and got the same results.
I
then
tried printing to the Immediate window (Debug.Print Forms![Purchase
Order]![Ship History subform].AllowEdits) and got a carriage return.
Thinking a Null might be the problem I used the Nz function and got the
same
result (a carriage return).

I've tried every combination of the above I could think of and tested
each
for both AllowEdits = True and AllowEdits = False. What am I doing
wrong???
I actually have a workaround for this situation, but I'd like to know
what's
going wrong; there are other times when I'd like to be able to
determine
whether the form is in "Edit" mode or not.

Thaks for all your help.

Kari

:

Not sure how you define "read-only", but you could test the AllowEdits
property of the form:
If Forms("frmExample").AllowEdits Then
MsgBox "read only"
Else
MsgBox "normal
End If

That should work if the form was opened this way:
DoCmd.OpenForm "frmExample",,,,acFormReadOnly

However, there are many other reasons a form might be read-only, such
as:
- It is based on a query that is not updatable.
- The user does not have write privileges.
- The database was opened read-only, or the drive or media is
read-only.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.


How do I determine if a form has been opened in read ony mode.

ie. If frmExample "Is opened as read only" then
do whatever
Else
do something else
End if

TIA,
Duncan
 
Back
Top