Hide buttons untill all controls have values

oxicottin

Learning by pecking away....
Local time
Today, 09:12
Joined
Jun 26, 2007
Messages
889
I have a form with a subform and in my form I have 13 controls that need to have data entered before a few buttons are displayed. In my On Current event I call Public Function ShowHideButtons() which shows the correct buttons.

The issue I'm having is on open if its a new record it doesn't show any buttons like it supposed to but when I get the 13 controls filled in in the Form Header It doesn't display any buttons BUT if I close that record and reopen it then the correct buttons are visible. How do I get the buttons to display. Im using the On Current and I thought it fired after you moved to each control.

Code:
Public Function ShowHideButtons()
 If Me.NewRecord Then
      Me.optInactiveORDeleteGroup.Visible = False
      Me.cmdAdmin.Visible = False
      Me.txtDeleteVWILOTO.Visible = False
      Me.cmdPrintVWI.Visible = False
      Me.cmdPrintSOC.Visible = False
      Me.cmdPrintLOTO.Visible = False
      Me.cmdPrintVWI.Visible = False
      Me.cmdPrintSOC.Visible = False
      Me.cmdPrintLOTO.Visible = False
      Me.cmdsendEmail.Visible = False
  Else
      Me.optInactiveORDeleteGroup.Visible = True
      Me.cmdAdmin.Visible = True
      Me.txtDeleteVWILOTO.Visible = True
  End If
 
If Me.cboCategories.Column(1) = "VWI" Then
      Me.cmdPrintVWI.Visible = True
      Me.cmdPrintSOC.Visible = True
      Me.cmdPrintLOTO.Visible = False
      Me.cmdsendEmail.Visible = True
      
ElseIf Me.cboCategories.Column(1) = "LOTO" Then
      Me.cmdPrintVWI.Visible = False
      Me.cmdPrintSOC.Visible = False
      Me.cmdPrintLOTO.Visible = True
      Me.cmdsendEmail.Visible = True

   End If
End Function
 
Hi. If you want the buttons to show on a new record, then you need to use True instead of False in the If Me.NewRecord section.
 
Im using the On Current and I thought it fired after you moved to each control.
No, it does not. It is a form event that fires when a record receives the focus, thus becomes the current record. This can happen in the chain of events when a form opens, or is requeried (either directly or by applying/removing a filter) or refreshed. It's also a report event.
 
theDBguy, I think I might need to explain this better. I have a form and subform. I have 13 controls on my form which are in my "Form Header". I also have a few button in my "Form Header" which I hide/show depending on the controls in the "Form Header". Now, if its a new record I don't want to show any of the buttons BUT if I have made a selection in all 13 controls and have moved on to its subform then I want the buttons to be visible and no longer hidden.

Micron, what form event could I use then?

Would I have to Call ShowHideButtons from each controls After Update?
 
Last edited:
Well, I think you do want to use the Current event if you're going to navigate from one record to another if I understand the goal (assuming you can/will be navigating). It just doesn't work the way that you implied. You would probably still want to use that event because when going from record to record you will want the buttons to exhibit according to your rule, yes? But you will need one or more other events as well but I'm not sure what will work best as it depends on how the user will interact with the forms. You could do a test after each of the 13 control OnLostFocus events assuming there is no control over the order in which they are updated. You could do the test on the subform control Enter event. You may need both or a combination of these and other events. Can a user enter all 13 data values and never click on the subform? Then what? By that I think you might see that we can't say with complete certainty because we don't know how the forms might be used.

If you need to test each control after it is edited, I suggest you don't create 13 events for this as there are more efficient ways we can cover. You might find the enter event is all you need.
 
Your DB sounds similar to mine.

You will need to call that function each and every time you want any of those things to happen.

Perhaps validation would work. After Update of each control, check to see if any tagged control has a value of null. Upon having no nulls, call the function.

Also, I prefer to use enabled rather than visible, because then a bunch of buttons don't magically appear out of nowhere.

EDIT: Micron also brings up a point - if you allow record navigation within the form, you'll need to call the function then, too.
 
this is the ans to post #4.
add code to the subform's On Enter event:

private sub yoursubformName_Enter()
call ShowHideButtons
end sub
 
IIRC, Enter event doesn't fire when a form has controls. That's why I suggested the subform control.
 

Users who are viewing this thread

Back
Top Bottom