?
Solved

Problem enabling button after record update Access 2007

Posted on 2014-09-17
2
Medium Priority
?
395 Views
Last Modified: 2014-09-17
I have a form that uses the following code when it loads:

Private Sub Form_Current()
Me!btn_cancel_time.Enabled = False
Me!btn_nevermind_time.Enabled = True
End Sub

Open in new window


Then does this when a change is made:

Private Sub Form_Dirty(Cancel As Integer)
Me!btn_cancel_time.Enabled = True
Me!btn_nevermind_time.Visible = False
End Sub

Open in new window


This works great. Problem is I have a button for saving the record and adding another:

Private Sub btn_add_time_Click()
DoCmd.GoToRecord acDataForm, "time_entry", acNewRec
Me.tar_abs.Visible = False
Me.excused.Visible = False
Me.reason.Visible = False
Me.Label44.Visible = False
Me.Label46.Visible = False
Me.Label48.Visible = False
Me!btn_cancel_time.Enabled = False
Me!btn_nevermind_time.Enabled = True
End Sub

Open in new window


All of the .visible code is working but I cant make it enable and disable the buttons back to the way they were when the form loaded the first time.
0
Comment
Question by:princeservice
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 48

Accepted Solution

by:
Dale Fye earned 1000 total points
ID: 40327760
What do you do with these controls if you are not on a new record?  I assume that those labels refer to the associated controls (cannot tell what type).

1.  First thing I would do is change the names of all those controls so that they have meaning.  Use one of the standard naming conventions so that when you look at your code, you can tell what labels are associated with which controls by their name and so that you can tell the type of control, by its name.  Example:

Text box: txt_something
Combo: cbo_something
Listbox: lst_something
Label   : lbl_something

2.  Then I would determine what you want to do with the visibilty of those controls if you are not on a new record.  

3.  Then I would move all of that code, except for the:
DoCmd.GoToRecord acDataForm, "time_entry", acNewRec

Open in new window

into the Form_Current event.  Use an if statement to determine whether the current record is new or not, and set the visibility of the controls based on that, something like:
Private Sub Form_Current

    if me.newrecord then
        Me.tar_abs.Visible = False
        Me.excused.Visible = False
        Me.reason.Visible = False
        Me.Label44.Visible = False
        Me.Label46.Visible = False
        Me.Label48.Visible = False
    Else
       'something else here
    End If

    Me!btn_cancel_time.Enabled = False
    Me!btn_nevermind_time.Enabled = True

End Sub

Open in new window

0
 
LVL 38

Assisted Solution

by:PatHartman
PatHartman earned 1000 total points
ID: 40327984
To finish Dale's thought - then to toggle the buttons after an update, use the Form's AfterUpdate event and call the Current event so you don't need to duplicate the code.

So you'll end up with code in
Current
Dirty
AfterUpdate (call Current)

None of the toggle code should go into your own button events.

The other reason for properly naming controls is so your code will be clear whether you are referring to a CONTROL or a field in the recordsource.  When you are setting a property, you are referring to the control.

And finally, using the dot syntax will give you intellisense which you don't get with the bang.
So use Me.btn_cancel_time.Enabled = True
 rather than Me!btn_cancel_time.Enabled = True
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question