Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Which event is best for triggering code to hide an invalid option? 2

Status
Not open for further replies.

postermmxvicom

Programmer
Jun 25, 2007
114
US
I have a form used for data entry. It is for making inventory adjustments. There is a combo box, where the user can select which inventory item to adjust.

Now, what I would like, is to have it so that whenever the combo box is blank (either because the user has deleted the information there OR because they have completed an entry and the form has moved on to a new blank record) that a certain button would be invisible.

Now, I can accomplish this, by placing code in multiple events, but my question is: Is there a single event where I could place this code only once to accomplish the same thing? Secondarily, if there is no such event: Should I be using a different pair of events, other than the two I have chosen (AfterUpdate on the combobox and Current on the form)?

Currently my code is as follows:

Private Sub FKLot_AfterUpdate()

If IsNull(Me.FKLot) Then
Me.ZeroOutLot.Visible = False
Else
Me.ZeroOutLot.Visible = True
End If

End Sub

Private Sub Form_Current()

If IsNull(Me.FKLot) Then
Me.ZeroOutLot.Visible = False
Else
Me.ZeroOutLot.Visible = True
End If

End Sub
 
The two events are well choosen, but you may simplify the code:
Private Sub FKLot_AfterUpdate()
Me!ZeroOutLot.Visible = Not IsNull(Me!FKLot)
End Sub

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV,

Thank you for the clever code reduction. But are you intimating that there is likely not a single place I could put this code, and that I will have to put it in two places?

Part of what is driving me crazy, is that I created a subform for displaying the current quantity of a given inventory item - and this automatically behaves precisely as I would like my button to do. Whenever the combo box is empty -regardless of how it became empty- it is gone, but whenever the combo box has data, the total subform shows up.

It makes me suspect very strongly that there is a single event that I can tie this code to, somehow - someway...
 
Isn't the subform linked ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV,

The subform is linked and behaves exactly as I want the button on my mainform to behave. Currently, the button also behaves as I want it to, but I want to know if there is a single event I could put the code for the button into instead of having it in two places.

I also must admit that I do not follow your line of questioning. I feel as though your last question was intended to lead me somewhere, but I do not follow.
 
My last question was to point out that probably no event procedure is in play but simply the builtin linking mechanism.
 

If I'm not mistaken, your subform updates immediately because it is linked.

Your code on the main form needs to be in two places because there are two methods that can cause it to run...
1. Moving to a new record - uses the FormCurrent version.
2. User deletion - uses the AfterUpdate version.


Randy
 
Thank you all (especially for your patience)

I am always impressed with the knowledgeable, friendly people here that make this place the best.

Aaron
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top