Invisible field stays on the screen when I go to next record

shanice

Registered User.
Local time
Today, 06:12
Joined
Mar 3, 2010
Messages
41
Hi

I have written a code for a field to become visible (it's set to invisible in the properties of the field) if it meets a certain requirement:

Private Sub Domain_AfterUpdate()

If Domain = "Partnerships for Systems Change and Policy Development" Then
Partners_Label.Visible = True
Partners.Visible = True

ElseIf Domain = "" Then
Activity_Label.Visible = False
Partners.Visible = False

End If
End Sub

Everything works but if the field is visible it stays on the screen when I go to the next record. How do I get it to go back to being invisible when I go to the next record?
 
In the form's On Current event put (in the VBA window):

Code:
    Domain_AfterUpdate
 
That didn't work. :-( Should I try putting the whole code in?
 
When you say "That didn't work" what actually happens? Do you get an error? What?
 
The field stays visible. This is what I put in:

Private Sub Form_Current()
Domain_AfterUpdate
End Sub
 
The whole point is that the code needs to run on both events, the Domain AfterUpdate AND the OnCurrent event of the form. So, Yes, you can put the code again in the OnCurrent event of the form.
As a side note.... I don't think I have ever seen one event called from another... Being the AfterUpdate of a text called from the OnCurrent of a form.... Does it work? What happens on a new record? Doesn't the AfterUpdate force the save of a blank record? :confused:
 
No the after update won't save a blank record. But you can call events from events. As long as they are on the same form you don't even have to make them PUBLIC but if they are on different forms then you have to make it public in order to call it from outside the scope of the form it is on.


Plus I would reference DOMAIN as Me.[Domain] as DOMAIN is a RESERVED WORD in Access and should not be used as a field or object name.
 
Just to add to this.
Private Sub Domain_AfterUpdate()

If Domain = "Partnerships for Systems Change and Policy Development" Then
Partners_Label.Visible = True
Partners.Visible = True

ElseIf Domain = "" Then
Activity_Label.Visible = False
Partners.Visible = False

End If
End Sub
It could be a problem with your logic. It never gets to the line because (I presume) that field would always contain something. So change that line to:
Code:
Else
Also remember to follow what SOS suggested, rename Domain.

By the way, you can't change the Visible property of a field, you change the Control that is bound to the field. ;)
 
Thank you all for your help! I got it to work. I appreciate your advice as well...it's been 10 years since I worked with vb.
 

Users who are viewing this thread

Back
Top Bottom