Private Sub Form_AfterUpdate()

  • Thread starter Thread starter david.smouts
  • Start date Start date
D

david.smouts

Hello,

I need to run this visual basic routine after
* I change the record
* I jump to another record
* I open the form
* ...

At this time I've got a button called "update" that calls this routine.
How do I automate this?
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
If Me.layout = "kennel" Then
Me.button1.Visible = True
Me.button2.Visible = True

Me.button3.Visible = False
Me.button4.Visible = False
Me.button5.Visible = False
End If
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
 
Hello,

I need to run this visual basic routine after
* I change the record
* I jump to another record
* I open the form
* ...

At this time I've got a button called "update" that calls this routine.
How do I automate this?
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
If Me.layout = "kennel" Then
Me.button1.Visible = True
Me.button2.Visible = True

Me.button3.Visible = False
Me.button4.Visible = False
Me.button5.Visible = False
End If
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

Half of the answer is in your title: call the code from the form's
AfterUpdate event. The other half of the answer is to also call the code
from the form's Current event.
 
The form's Current event should take care of the second two points. The
first point could be addressed with the After Update event for the control
(e.g. text box) bound to Layout. If Me.layout is something other than
"kennel", are the visible properties reversed, so that 1 and 2 are not
visible, and 3-5 are? If so, you could do something along the lines of
setting the visible properties to True on the property sheets for all five
buttons, then have code like:

If Me.layout = "kennel" Then
Me.button1.Visible = True
Me.button2.Visible = True
Me.button3.Visible = False
Me.button4.Visible = False
Me.button5.Visible = False
Else
Me.button1.Visible = False
Me.button2.Visible = False
Me.button3.Visible = True
Me.button4.Visible = True
Me.button5.Visible = True
End If

Another approach would be to use each command button's Tag property. In
this example, the tag value for buttons 1 and 2 is 2, and for 3-5 it is 1 (I
think I got that right):

Dim ctl As Control
For Each ctl In Me.Controls
If ctl.Tag = 1 And Me.layout = "kennel" Then
ctl.Visible = False
Else
ctl.Visible = True
If ctl.Tag = 2 And Me.layout <> "kennel" Then
ctl.Visible = False
Else
ctl.Visible = True
End If
End If
Next ctl

I think that in any case you need to specify either visible or not for each
record (the Else part of the statement); otherwise a hidden control will
remain hidden, no matter the value in Layout. There may be a more efficient
way of handling that code, but the general idea works.
If you need to use the code from both the form's Current event and the text
box's After Update event (or the form's Before Update event or whatever) you
could set up the code as a general procedure (Insert > Procedure from the
code window menu), then call the procedure's name from the various events.
If the procedure is named ButtonHide your line of code in the form's Current
event would be:

Call ButtonHide
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top