Results 1 to 3 of 3
  1. #1
    awhit22 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    May 2011
    Posts
    5

    Help with form Update Code

    Hi There,

    I'm using access 2010 to create a Simple Asset DB for some of our server resources. Basic tracking of type of Server, IPs, ILO Address, Asset Info, etc. I have one main table with server info, then I have a few linked tables that I pull data from. Data like location and Type of server.
    I created a datasheet form for quick access.



    I'm trying to use the after update event procedure to perform certain actions after a field is updated.

    For example, I have a combo box on each record, that I select Virtual or Physical server. Those values are based on a typetable. Based on the value in that field, I want to be able to disable or enable the ILO address field on the form. I'm using a a simple if then statement

    If Me.nodeType = 1 Then
    Me.nodeILO.Enabled = False
    Me.nodeILO2.Enabled = False
    Else
    Me.nodeILO.Enabled = True
    Me.nodeILO2.Enabled = True
    End If

    The problem is that when I update the type field for one record, it changes the enabled state for all records and not just that one.

    Is there a way to only disable the fields for the current record?

    I also have a set of cascading combo boxes, which are working, except, when I change one it resets the value for all the other records.

    I'm attaching a copy of the database if you'd like to see what I have.

    Thanks in advance.

    -Adam

  2. #2
    maximus's Avatar
    maximus is offline Expert
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    Here is a very simple example. I have a Form with a combobox A and two text Box B and C. Whe I select 2 in the Combo Box a B is disables and When I select 3 C is disabled. Whe one of the text box is disabled the other is enabled simultaneously.

    I have placed two codes on the AfterUpdate Event of the Combobox and a Second Piece of code on the On Current Event Of my form which ensures:

    1) The correct Control is Disabled according to the value of A when I navigate.
    2) Both The controls are enabled when I open a new record.

    The codes are as below.



    Private Sub A_AfterUpdate()
    Select Case Me.A
    Case Is = 2
    Me.B.Enabled = False
    Me.C.Enabled = True
    Case Is = 3
    Me.B.Enabled = True
    Me.C.Enabled = False
    End Select
    End Sub



    Private Sub Form_Current()

    If Me.NewRecord Then
    Me.B.Enabled = True
    Me.C.Enabled = True
    Else
    Select Case Me.A
    Case Is = 2
    Me.B.Enabled = False
    Me.C.Enabled = True
    Case Is = 3
    Me.B.Enabled = True
    Me.C.Enabled = False
    End Select
    End If

    End Sub

  3. #3
    awhit22 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    May 2011
    Posts
    5

    Solved

    Yep, this work exactly as expected. Thanks for your help.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Update Statement in form code
    By ksmith in forum Programming
    Replies: 9
    Last Post: 11-07-2011, 12:04 PM
  2. Before Update code
    By jms in forum Forms
    Replies: 1
    Last Post: 03-10-2011, 11:28 AM
  3. Replies: 6
    Last Post: 11-05-2010, 10:11 AM
  4. Replies: 3
    Last Post: 04-14-2010, 10:07 AM
  5. Code to Update Excel from Access
    By portmancp in forum Programming
    Replies: 2
    Last Post: 03-10-2010, 03:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums