Open a form with all date disabled

G

Guest

I have a form with text boxes and combo boxes on. When the "Status" combo box
value is "Closed" i want the form to open with every txt box and combo box
(Including the "Status" Combo box) disabled so that no fields can be changed.
Read Only.

Does anyone know any code that will do this???
 
J

Jeff Boyce

If you add a procedure to the OnCurrent event, you can use that to check the
contents of the row/record as it is being loaded to the form.

It sounds like you want to set the form's Data Edit property to "No" if your
status field value corresponds to "Closed". A simple If... Then statement
could handle this.
 
G

Guest

Could you please write the code for a simple if.. then statement as im not
familiar with the code as im just getting use to Access
 
J

Jeff Boyce

If you are going to be working in Event Procedures, it would be worth your
time to learn a little about VBA... Otherwise, if someone just writes your
code, then tells you where it goes, then tells you how to debug it if/when
it doesn't work exactly right the first time, then ..., you'll have little
incentive to learn it and you certainly won't understand it!

Or you could check with a local area users group for someone for hire...

Regards

Jeff Boyce
<Access MVP>
 
G

Guest

Thanks for NO help. I am trying to learn VBA but it takes time. If im not
sucessful in writing my own code then that's when i ask for someones
assistance and when the code is right, i will then teach myself how it works
and what i was doing wrong.
 
J

Jeff Boyce

Thanks for clarifying. I'm not sure how I or any of the other newsgroup
readers would have known that based on your earlier posts.

One approach might be:

If Me!cboYourStatusFieldName = "Closed" Then
Me.AllowEdits = False
Else
Me.AllowEdits = True
End if

Do you think the rude post is likely to encourage other folks to respond?
Folks who respond in this newsgroup are largely volunteers, and aren't paid
to be polite... we do so out of courtesy.

Good luck

Jeff Boyce
<Access MVP>
 
G

Guest

Thank you for responsing even thou i was rude. i will apoligise for my
comments but i was offended by your comment "Or you could check with a local
area users group for someone for hire...", i took it as, if i cant write code
then hire someone that can.

Regards

StuJol
 
J

Jeff Boyce

Sorry you found the comment offensive.

If I can't figure out how to get something done, I find someone who can.
That sometimes means hiring, especially if I'm in a hurry.

Regards

Jeff Boyce
<Access MVP>
 
G

Guest

Now that we are back on good terms (I think) i would like to discuss further
the code you surgested. I understand if you dont reply

I used the following code

Private Sub Form_Open(Cancel As Integer)
If Me!cboStatus = "Closed" Then
Me.AllowEdits = False
Else
Me.AllowEdits = True
End if
End Sub

Bit it didnt reconise Me!cboStatus so i removed the cbo and left it as
Status (which is the name of the combo box) I've tried to find what cbo means
but are unable to find it in help. i can only assume it is short hand for
combobox and does not serve as any kind of control. Anyhow when i put my form
into run mode i am not able to edit any fields no matter what the status of
the status combo is. When i change the code to

Private Sub Form_Open(Cancel As Integer)
If Me!cboStatus = "Closed" Then
Me.AllowEdits = True
Else
Me.AllowEdits = False
End if
End Sub

Then when i run the form i can do edits no matter what the status of the
status combo box is. Its as if the code isnt reading the status of the combo
box. Any idea's please
 
J

Jeff Boyce

(see responses in-line below)

StuJol said:
Now that we are back on good terms (I think) i would like to discuss further
the code you surgested. I understand if you dont reply

I used the following code

Private Sub Form_Open(Cancel As Integer)
If Me!cboStatus = "Closed" Then
Me.AllowEdits = False
Else
Me.AllowEdits = True
End if
End Sub

Bit it didnt reconise Me!cboStatus so i removed the cbo and left it as
Status (which is the name of the combo box) I've tried to find what cbo means
but are unable to find it in help. i can only assume it is short hand for
combobox and does not serve as any kind of control. Anyhow when i put my form
into run mode i am not able to edit any fields no matter what the status of
the status combo is. When i change the code to

The example was only an example -- and you realized that you needed to use
the name of your control. I use a prefix on my controls to remind me what
type of control they are (and "cbo" is short for "combo box").
Private Sub Form_Open(Cancel As Integer)
If Me!cboStatus = "Closed" Then
Me.AllowEdits = True
Else
Me.AllowEdits = False
End if
End Sub

Then when i run the form i can do edits no matter what the status of the
status combo box is. Its as if the code isnt reading the status of the combo
box. Any idea's please

From your description, you are working to handle the situation when the form
first opens. This doesn't help you when you change the status, nor when you
load a new record. To handle those two events, you'd need to add code to
the combo box's AfterUpdate event, and to the form's "Current" event. You
may not need to do the code in the form's "Open" event.

Regards

Jeff Boyce
<Access MVP>
 
G

Guest

Thanks for the quick response. It is very much appreciated.

I already have code in the autoupdate event. When you select "Closed" from
the combobox it disables all fields on my form. Which is what i wanted to do.
The problem is when i reopen the form and view a record who's status combo
box is "Closed" then all fields are enabled. When i open my form and view my
records, all records that have "Closed" in the status field I dont want to be
able to EDIT.

I have also ordered a couple of ACCESS VBA books off the net so hopefully i
will be able to gain some knowledge from those.
 
J

Jeff Boyce

I'm not sure what your form & code are doing then.

If I were faced with this circumstance, I would set breakpoints in my
procedures and make sure that they were firing when I thought they
were/should. This would at least confirm whether the code is running.

Regards

Jeff Boyce
<Access MVP>
 

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