Solved

Problem enabling button after record update Access 2007

Posted on 2014-09-17
2
391 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 47

Accepted Solution

by:
Dale Fye (Access MVP) earned 250 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 37

Assisted Solution

by:PatHartman
PatHartman earned 250 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

737 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