Results 1 to 11 of 11
  1. #1
    Sonu is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Aug 2019
    Posts
    35

    Forms Before Update/After Update Events

    Hello All,



    I have a Sub-Form which has a Combo Box and 5 command buttons. The buttons are by default Disabled when the sub-form is opened. The Combo Box contain 20 unique values and I have set an After Update event to enable only the required button based on the Combo Box selection (Ex: if the Value is 1, then enable Command_1). The Combo Box value is stored in a back-end table. - This is working as expected.

    FYI - The combo box will always have some value to display when the sub-form is opened because it is associated with a main form (based on previous input value).

    Now, what I need - When the main form opens, the sub-form will show the earlier selected value in the combo box - I need the related button enabled if it is matching the selected value.

    For ex: Main form - Sub-form - Combo box Value display as 1 - > I need Command_1 in enable mode.

    As I mentioned that I have Disabled all those button by default on open, will a Before Update event be helpful here and how do I use that?

    Thank You,

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    will a Before Update event be helpful here
    Not if you want this to happen when the form opens. Suggest the Load event of the form. At that point, its data has been loaded whereas in the Open event, it has not so no point trying to do this in the Open event IMHO.
    If I knew I was going to end up here at the outset, I would have created one function to accept the combo value as a parameter, and assign that value in 6 cases - form load + 5 button click events. I suppose you already have 5 events with pretty much the same code and will want to continue on that path. So enable the button that matches the combo value in form Load. If it is not a sure thing that the combo will always have a value on form load, then your code should deal with the possibility.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    PMFJI,

    Quote Originally Posted by Sonu View Post
    FYI - The combo box will always have some value to display when the sub-form is opened because it is associated with a main form (based on previous input value).
    I'm not sure what yo mean by "sub-form".

    Let's say there are two forms: "frmMain" and "frmOrders". "frmOrders" is associated with "frmMain" in the fact that "frmOrders" is embedded in "frmMain" through the use of a sub form control.

    A form is not a sub-form just because you opened it from the main form. So you do not OPEN a sub-form, it is displayed (in the sub form control) just like data in a text box, when the main form is opened.

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    I re-read and still don't come to that conclusion because to me, "When the main form opens, the sub-form will show the earlier selected value in the combo box" seems like a normal form/subform relationship. Then again, I suppose there's a chance that the subform is already open. I guess we'll have to wait for an explanation.

  5. #5
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    @Micron,
    What threw me was the "when the sub-form is opened".
    How do you "OPEN" a sub form? OPEN the main form, sure. But "OPEN" a sub form???????

    Maybe it is me being too literal??!!

  6. #6
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,016
    I read it that way, too, and thought the OP was talking about opening a second form (what he called a 'subform') from the first form.

    We really need to get this cleared up by @Sonu.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  7. #7
    Sonu is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Aug 2019
    Posts
    35
    I am sorry about the confusion here..I was so much into the issue and could not write it properly.. Let me put it again.


    Yes- One form is associated/embedded (highlighted in orange color) within another form.


    The '...Code' combo box controls the buttons (disabled by default). Only for a certain selection, any one of the button gets enabled.


    Let say at once instance of this form, I select a value in the combo box, the related button is enabled and save+exit from the screen (the combo box selection is stored in back-end table).


    Next time, when I open it again, the combo box shows me the earlier selected value (as it was saved before) but the related button shows as Disabled. I want the related button also in Enable mode.


    That's why I tried to use Before Update, if the combo box value is in the 'certain list', show the related button in Enable mode.


    I hope, I was able to clear the confusion..


    Thank you,
    SonuClick image for larger version. 

Name:	Issue.png 
Views:	21 
Size:	28.5 KB 
ID:	40176

  8. #8
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    I'm not sure what event to recommend as the design seems unclear. It looks like you have a main form>subform>tab control>subform thing going on. There are options as far as code is concerned, one being

    Code:
    Select Case Me.cmbName
      Case Is = 1
        Me.cmd1.Enabled = True
      Case Is = 2
        Me.cmd2.Enabled = True
      etc
    End Select
    Where to put this? I can't tell if the form in question has record selectors or not, or if displayed records depend on some other part. I no longer think the Load event is the place.
    Perhaps form Current event so that the correct button is enabled not just when the form opens but as you navigate from record to record as well. However, what happens if the user alters the combo selection? Now we need this in the combo AfterUpdate event too. But now the 1st button is still enabled and likely the appropriate one gets enabled as well.

    To handle the latter problem, I'd have a small sub in the form module that disables these buttons, and in the enabling code, call that sub. Thus, all buttons get disabled first, then desired one gets enabled. Thus in the form current (?) and combo afterupdate events:
    Code:
    ButtonDisable
    
    Select Case Me.cmbName
      Case Is = 1
        Me.cmd1.Enabled = True
      Case Is = 2
        Me.cmd2.Enabled = True
      etc
    End Select
    
    Private Sub ButtonDisable()
    With Me
     .cmd1.Enabled = False
     .cmd2.Enabled = False
     .etc
    End With
    End Sub
    Hope some of that helps. Obviously you need to substitute my guesses at your control names with your own control names. Just to be clear, for a situation involving multiple controls with repeated code I would use a different approach altogether.
    Last edited by Micron; 11-15-2019 at 09:02 AM. Reason: clarification & correction
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  9. #9
    Sonu is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Aug 2019
    Posts
    35
    Thank you micron, I am going to try it and will come back soon.

  10. #10
    Sonu is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Aug 2019
    Posts
    35
    The suggested approach worked very well. Thank you, But as you suggested, now I will try to find an alternate approach to do this, to avoid repetitive code.

  11. #11
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Upon review of my code post I see that it can be interpreted incorrectly. Only the sub call ButtonDisable would go into both events. The sub itself just once in the form code.
    As for how else to do this, one approach is to put a value in the Tag property (see property sheet) of the controls you want to affect. Then you loop through the form's controls and if it is of the type you're looking for (e.g. button,textbox) you do whatever IF the tag property = the word you've used for that property.

    In your case, it probably doesn't make sense at this point unless the intent is to be a learning exercise.

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

Similar Threads

  1. Replies: 15
    Last Post: 12-08-2017, 05:32 PM
  2. Update events from calculated fields
    By andy49 in forum Forms
    Replies: 4
    Last Post: 02-14-2017, 03:12 PM
  3. Time Validation - Before Update Events
    By pjstrat00 in forum Access
    Replies: 3
    Last Post: 06-12-2014, 03:50 PM
  4. 2 forms and one subform update
    By jwd in forum Forms
    Replies: 6
    Last Post: 11-20-2012, 07:08 PM
  5. Writing Code for "After Update" Table Events
    By dipique in forum Programming
    Replies: 10
    Last Post: 07-09-2012, 08:11 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