Same Form Add/Edit/Read Only

L

lbernarde

I have a form that I am using for Add/Edit and Read Only. I have the add and
editing working well, however, the read only is causing a problem. I am able
to get the entire form to be read only using VBA, but I want the user to be
able to select a combo box on the form to move around thru records. Because
I have the allowedits to no, the box will drop down, but you are unable to
select an option to view that record. Any ideas on how to do this without
having to set each field (there are lot of fields and subforms) individually?
Thanks Much!
 
D

Dirk Goldgar

lbernarde said:
I have a form that I am using for Add/Edit and Read Only. I have the add
and
editing working well, however, the read only is causing a problem. I am
able
to get the entire form to be read only using VBA, but I want the user to
be
able to select a combo box on the form to move around thru records.
Because
I have the allowedits to no, the box will drop down, but you are unable to
select an option to view that record. Any ideas on how to do this without
having to set each field (there are lot of fields and subforms)
individually?


There are two main approaches to this. The first is to use a code loop to
set the Locked property of all the data fields, but not the combo box. A
simple loop would look like this:

Dim ctl As Access.Control

' Ignore errors for controls that don't have
' a Locked property
On Error Resume Next

For Each ctl in Me.Controls
If ctl.Name <> "cboFind" Then
ctl.Locked = True
End If
Next ctl

The other approach is to use the Enter event of the combo box to set the
form's AllowEdits property to True, and the Exit event to set it back to
False (or to what it previously was -- you may need to preserve that). This
also works, and is reasonably simple to do.
 
L

lbernarde

Thanks for the code. I really want to use the code that loops thru the
controls. I'm entering the form thru a main menu. I tried adding the code
in the on click of the main menu, got invalid use of me, which made sense, so
I replaced me with the form name. I then get the error object doesn't
support this property or method. It looks like it is a label. How do I
handle this?
Thanks
 
D

Dirk Goldgar

lbernarde said:
Thanks for the code. I really want to use the code that loops thru the
controls. I'm entering the form thru a main menu. I tried adding the
code
in the on click of the main menu, got invalid use of me, which made sense,
so
I replaced me with the form name. I then get the error object doesn't
support this property or method. It looks like it is a label. How do I
handle this?

You need to use a reference to the form, which isn't *quite* as simple as
just replacing "Me" with the form name -- but almost. If the code is
executing on the menu form, and you want to manipulate the controls on
another form named "YourFormName" (which you have already opened), you can
do it like this:

Dim ctl As Access.Control

' Ignore errors for controls that don't have
' a Locked property
On Error Resume Next

For Each ctl in Forms!YourFormName.Controls
If ctl.Name <> "cboFind" Then
ctl.Locked = True
End If
Next ctl
 

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