Code to make form Read Only

D

dee

Hi have a main form which contains a sub form, which Tina in these newsgroups
helped me create.

Once the main form information is filled in, and the user hits Tab to go to
the sub-form, an append query causes the correct table to be populated with
questions that relate to the questionnaire number in the main form. The data
entry person then inputs the responses to the questions.

It works very well. However, if the data entry person starts mucking around
with the top (main) form, for example, if they select another name, thinking
(mistakenly) that the questionnaire for that person will appear, what it does
instead is modify the underlying data so that the responses that were
originally linked to John Doe are now linked to Mary Smith.

Is there a way that once the sub form has been populated for a person that
the main form becomes "read only" - unchangeable?

VBA isn't my strong suit (understatement).

Any help would be GREATLY appreciated.
 
A

Allen Browne

Dee, see:
Locking bound controls on a form and subforms
at:
http://allenbrowne.com/ser-56.html

The idea is that the form and subform come up locked, and you click a button
to unlock and edit it. The unbound controls (e.g. those you use for
filtering) still work, which is not the case if you just set the form's
AllowEdits property to No.
 
D

dee

Hi and thanks for your response.

I already have:

DoCmd.Restore
in OnLoad. I pasted this after it to end up with:
rivate Sub Form_Load()

DoCmd.Restore
=LockBoundControls([my_main_form_name],True)

I get a syntax error when I open the form. I'm very obviously doing
something wrong (no big surprise!) :)

Maybe it's the end of a very long day, but I'm obviously missing something.
End Sub

--
Thanks!

Dee


Allen Browne said:
Dee, see:
Locking bound controls on a form and subforms
at:
http://allenbrowne.com/ser-56.html

The idea is that the form and subform come up locked, and you click a button
to unlock and edit it. The unbound controls (e.g. those you use for
filtering) still work, which is not the case if you just set the form's
AllowEdits property to No.
 
A

Allen Browne

To call the code in the event procedure (rather than just setting the
property), use:

Call LockBoundControls(Me, True)

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

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

dee said:
Hi and thanks for your response.

I already have:

DoCmd.Restore
in OnLoad. I pasted this after it to end up with:
rivate Sub Form_Load()

DoCmd.Restore
=LockBoundControls([my_main_form_name],True)

I get a syntax error when I open the form. I'm very obviously doing
something wrong (no big surprise!) :)

Maybe it's the end of a very long day, but I'm obviously missing
something.
End Sub

--
Thanks!

Dee


Allen Browne said:
Dee, see:
Locking bound controls on a form and subforms
at:
http://allenbrowne.com/ser-56.html

The idea is that the form and subform come up locked, and you click a
button
to unlock and edit it. The unbound controls (e.g. those you use for
filtering) still work, which is not the case if you just set the form's
AllowEdits property to No.
 
D

dee

Hi Allen,

I'm almost there. The control is working in that it switches between Lock
and Unlock and doesn't give me any errors. However, the form doesn't
actually unlock.

Any other suggestions? Thanks so much for your time.
--
Thanks!

Dee


Allen Browne said:
To call the code in the event procedure (rather than just setting the
property), use:

Call LockBoundControls(Me, True)

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

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

dee said:
Hi and thanks for your response.

I already have:

DoCmd.Restore
in OnLoad. I pasted this after it to end up with:
rivate Sub Form_Load()

DoCmd.Restore
=LockBoundControls([my_main_form_name],True)

I get a syntax error when I open the form. I'm very obviously doing
something wrong (no big surprise!) :)

Maybe it's the end of a very long day, but I'm obviously missing
something.
End Sub

--
Thanks!

Dee


Allen Browne said:
Dee, see:
Locking bound controls on a form and subforms
at:
http://allenbrowne.com/ser-56.html

The idea is that the form and subform come up locked, and you click a
button
to unlock and edit it. The unbound controls (e.g. those you use for
filtering) still work, which is not the case if you just set the form's
AllowEdits property to No.

Hi have a main form which contains a sub form, which Tina in these
newsgroups
helped me create.

Once the main form information is filled in, and the user hits Tab to
go
to
the sub-form, an append query causes the correct table to be populated
with
questions that relate to the questionnaire number in the main form.
The
data
entry person then inputs the responses to the questions.

It works very well. However, if the data entry person starts mucking
around
with the top (main) form, for example, if they select another name,
thinking
(mistakenly) that the questionnaire for that person will appear, what
it
does
instead is modify the underlying data so that the responses that were
originally linked to John Doe are now linked to Mary Smith.

Is there a way that once the sub form has been populated for a person
that
the main form becomes "read only" - unchangeable?

VBA isn't my strong suit (understatement).
 
A

Allen Browne

Will have to let you do your debugging, Dee.

Temporarily disable any error handler.
Add the line STOP to the top of the code.
Then run it. When it stops, press F8 to single-step through and see what's
going on.

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

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

dee said:
Hi Allen,

I'm almost there. The control is working in that it switches between Lock
and Unlock and doesn't give me any errors. However, the form doesn't
actually unlock.

Any other suggestions? Thanks so much for your time.
--
Thanks!

Dee


Allen Browne said:
To call the code in the event procedure (rather than just setting the
property), use:

Call LockBoundControls(Me, True)

dee said:
Hi and thanks for your response.

I already have:

DoCmd.Restore
in OnLoad. I pasted this after it to end up with:
rivate Sub Form_Load()

DoCmd.Restore
=LockBoundControls([my_main_form_name],True)

I get a syntax error when I open the form. I'm very obviously doing
something wrong (no big surprise!) :)

Maybe it's the end of a very long day, but I'm obviously missing
something.
End Sub

--
Thanks!

Dee


:

Dee, see:
Locking bound controls on a form and subforms
at:
http://allenbrowne.com/ser-56.html

The idea is that the form and subform come up locked, and you click a
button
to unlock and edit it. The unbound controls (e.g. those you use for
filtering) still work, which is not the case if you just set the
form's
AllowEdits property to No.

Hi have a main form which contains a sub form, which Tina in these
newsgroups
helped me create.

Once the main form information is filled in, and the user hits Tab
to
go
to
the sub-form, an append query causes the correct table to be
populated
with
questions that relate to the questionnaire number in the main form.
The
data
entry person then inputs the responses to the questions.

It works very well. However, if the data entry person starts
mucking
around
with the top (main) form, for example, if they select another name,
thinking
(mistakenly) that the questionnaire for that person will appear,
what
it
does
instead is modify the underlying data so that the responses that
were
originally linked to John Doe are now linked to Mary Smith.

Is there a way that once the sub form has been populated for a
person
that
the main form becomes "read only" - unchangeable?

VBA isn't my strong suit (understatement).
 
D

dee

Thanks - I'll keep working with it to see if I can figure it out.

I appreciate your help.
--
Thanks!

Dee


Allen Browne said:
Will have to let you do your debugging, Dee.

Temporarily disable any error handler.
Add the line STOP to the top of the code.
Then run it. When it stops, press F8 to single-step through and see what's
going on.

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

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

dee said:
Hi Allen,

I'm almost there. The control is working in that it switches between Lock
and Unlock and doesn't give me any errors. However, the form doesn't
actually unlock.

Any other suggestions? Thanks so much for your time.
--
Thanks!

Dee


Allen Browne said:
To call the code in the event procedure (rather than just setting the
property), use:

Call LockBoundControls(Me, True)

Hi and thanks for your response.

I already have:

DoCmd.Restore
in OnLoad. I pasted this after it to end up with:
rivate Sub Form_Load()

DoCmd.Restore
=LockBoundControls([my_main_form_name],True)

I get a syntax error when I open the form. I'm very obviously doing
something wrong (no big surprise!) :)

Maybe it's the end of a very long day, but I'm obviously missing
something.
End Sub

--
Thanks!

Dee


:

Dee, see:
Locking bound controls on a form and subforms
at:
http://allenbrowne.com/ser-56.html

The idea is that the form and subform come up locked, and you click a
button
to unlock and edit it. The unbound controls (e.g. those you use for
filtering) still work, which is not the case if you just set the
form's
AllowEdits property to No.

Hi have a main form which contains a sub form, which Tina in these
newsgroups
helped me create.

Once the main form information is filled in, and the user hits Tab
to
go
to
the sub-form, an append query causes the correct table to be
populated
with
questions that relate to the questionnaire number in the main form.
The
data
entry person then inputs the responses to the questions.

It works very well. However, if the data entry person starts
mucking
around
with the top (main) form, for example, if they select another name,
thinking
(mistakenly) that the questionnaire for that person will appear,
what
it
does
instead is modify the underlying data so that the responses that
were
originally linked to John Doe are now linked to Mary Smith.

Is there a way that once the sub form has been populated for a
person
that
the main form becomes "read only" - unchangeable?

VBA isn't my strong suit (understatement).
 

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