Form View using snapshot?

G

Guest

I have one form. On the switchboard I have three choices. Add, Edit or
Search the form.
The add and edit work fine. My problem is with the search. If I open the
form in edit mode and manually change the recordset to snapshot I get what I
want which is to have the user search the form, still use the filter command
buttons on the form and not be able to make any changes to the textboxes on
the form.
I tried to write a sub procedure to do this automatically but I don't
understand what I'm doing. I also tried DoCmd in acReadOnly but it would not
allow me to use the filters on the form. I either need help writing a
procedure or a suggestion on another approach.
 
A

Allen Browne

A fairly simple workaround is to set the Locked property of the bound
controls instead of trying to modify the type of recordset the form uses.

As well as solving your immediate problem, this also avoids the display bugs
that occur in Access when the Detail section of a form goes completely blank
(because there were no records to show, and you can't add new records to the
read-only recordset), and so it also gets confused about the controls in the
(still visible) form header/footer.

Here's an example of code that loops through the controls on a form and
locks/unlocks the bound controls:
http://allenbrowne.com/ser-56.html
The example shows how to set this up with the click of a button, but in your
case you probably want to do this by passing something in the OpenArgs of
OpenForm, and then responding to it in Form_Open (or possibly by setting a
public variaable.)
 
G

Guest

Thanks Allen. The code does work and I'll be able to use it but I do need
the form to be automatically locked when the form opens. The users are a bit
careless generally so I don't expect them to remember to press the lock
button every time. Any further help you can give me would be greatly
appreciated. As much as I study VBA I don't quite grasp it so I don't know
where to put openArgs or what they should be.
 
A

Allen Browne

Just run the locking code in the Load event of the form.
Then it comes up locked every time it's opened.
 
G

Guest

I see. My default is locked and since I'm pretty much the only one who needs
to edit or add I can physically unlock it. Duh! Thanks again Allen. I'll
just blame my lack of good logic on menopause.
 

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