Page 1 of 2 12 LastLast
Results 1 to 15 of 24
  1. #1
    snipe's Avatar
    snipe is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    287

    VBA changing a few control properties

    Hey guys,



    I have a check box on a form to designate that a salesperson is in training. Default value is 0. When the box is checked, it locks and disables a few controls on the form and it opens up a pop up form to input some extra info. That pop up has a save/close button and a cancel/close button. The cancel button closes the pop up and sets the value of the check box back to 0. The controls stay locked and disabled, though, which I don't want.

    I have the following code on the after-update for the check box:
    Code:
    Private Sub TCheck_AfterUpdate()
    If Me.TCheck = -1 Then
        DoCmd.OpenForm "TrainingEntry"
        Me.ETimeHours.Locked = True
        Me.ETimeHours.Enabled = False
        Me.ETimeHours.BackColor = vbWhite
        Me.CommWages.Locked = True
        Me.CommWages.Enabled = False
        Me.CommWages.BackColor = vbWhite
        
        Else
        Me.ETimeHours.Locked = False
        Me.ETimeHours.Enabled = True
        Me.ETimeHours.BackColor = vbYellow
        Me.CommWages.Locked = False
        Me.CommWages.Enabled = True
        Me.CommWages.BackColor = vbYellow
    
    
        Me.TrComm = 0
    End If
    End Sub
    How can I revert the control properties back to the original values (of when check box is 0) when the pop up is closed? I know I could do it with a bunch of extra code on the cancel/close button on the pop up form, but I am assuming there is an event on the main form that I can use or something.

    thanks!

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Is it always unlocked when you return from the PopUp or just when the Cancel/Close is used?

  3. #3
    snipe's Avatar
    snipe is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    287
    Always. Checking the box on the main form fires the AfterUpdate event and changes the properties. When the cancel/close button is used, it sets the check box value back to 0, but it doesn't fire the After Update event, so that If/Then doesn't fire.

  4. #4
    snipe's Avatar
    snipe is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    287
    Speaking of, I just disabled the close button on the pop up.

  5. #5
    snipe's Avatar
    snipe is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    287
    Tried to use GotFocus on the original form, that didn't work.

    I figured that event would fire when the pop up closed.

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    The events *only* fire with user intervention, not code. How did you lock the control in the first place since you cannot lock the control with the focus?

  7. #7
    snipe's Avatar
    snipe is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    287
    Quote Originally Posted by RuralGuy View Post
    The events *only* fire with user intervention, not code. How did you lock the control in the first place since you cannot lock the control with the focus?
    With the code in the first post. The user checks the box.

    The only way that the Else commands fire is if the user checks the box, brings up the pop up, hits the save and close button, and then unchecks the box. That works great. It just doesn't work when the user hits the cancel button.'


    Guess I just need to add those Else commands to the Cancel/close button? Any other way that you can think of?

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I don't see where the code is locking the "TCheck" CheckBox, or are we talking about a different CheckBox?

  9. #9
    snipe's Avatar
    snipe is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    287
    Quote Originally Posted by RuralGuy View Post
    I don't see where the code is locking the "TCheck" CheckBox, or are we talking about a different CheckBox?
    Oh the check box is never locked. The values that get locked are hours and commission (for now; more to be added once I figure this out).

    In a nutshell: If a salesperson is in training, quite a few aspects of their pay change. So the pop up does all the work for the user. Save/close pushes that data to the fields of the main form. The data that gets pushed shouldn't get edited by the user since there were back end calculations done to get those values. So the normally-unlocked values (hours, commission, etc) get locked. If the user made a mistake and didn't mean to put the salesperson in "training mode" they just uncheck the box. The reason for the backcolor change is that only yellow fields can be edited.

    Make a bit more sense?

  10. #10
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Did you know that if you use this form of command:
    DoCmd.OpenForm "TrainingEntry", , , , , acDialog
    that the code will stop right here until the TrainingEntry form is either closed or made invisible?

  11. #11
    snipe's Avatar
    snipe is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    287
    That part already works fine. I have the popup set with Modal:Yes. The "Then" part of the If/Then all works fine. The popup appears, and the desired controls get locked. Its only the "Else" that isn't working.

    I am just going to add the unlocking code to the cancel button. Should fix the problems for now.

  12. #12
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    The point I was trying to make was that when Modal, Access will not let the focus off of the form unless you close it or make it invisible.

  13. #13
    snipe's Avatar
    snipe is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    287
    Ohhhhh so switching from Modal to acDialog should fire the GotFocus event. Testing now..

  14. #14
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    If the user is locked on the TrainingEntry form until it is close then doesn't that eliminate the need to lock any controls?

  15. #15
    snipe's Avatar
    snipe is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    287
    No. Setting the popup Modal to yes accomplished forcing the user to save or cancel the popup, they couldn't use a different form until that one was closed. Once the user is done in TrainingEntry, I need to lock the hours, commission, bonus, and draw values. If a salesperson isn't in training, the user just types in the value based on a few reports they run; its very simple and straightforward. If they are in training, certain values are multiplied by others, certain values don't apply, and bonuses are cut in half since they are getting an hourly wage. The entries all need to be done in the training entry to be sure that all the correct calculations are being done. If the entries are modified manually (and incorrectly), it will throw off the paycheck of the trainee.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 12-03-2013, 02:59 AM
  2. Changing control property
    By mujaqo in forum Programming
    Replies: 2
    Last Post: 05-23-2013, 09:41 AM
  3. Replies: 1
    Last Post: 04-12-2013, 07:56 AM
  4. Replies: 4
    Last Post: 02-09-2013, 09:26 AM
  5. Control properties for Menu Command
    By Pam Buckner in forum Access
    Replies: 1
    Last Post: 10-20-2011, 01:49 PM

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