Private Sub Form_Load() Me.AirportDiagramLoc.Visible = False Me.FirstChoiceAircraft.Visible = False Me.ProfilePicture.Visible = False End Sub
So when I open the Form these 3 Fields are inactive, I have buttons to make them re-appear again but what I would like to do as well is when a key Field is empty or Null then I would like them to re-appear automatically.
When I add a new Record All the Fields are empty anyway, but keying a particular Field will also help me out when I've entered all the information in the Form itself and have left out entering in that one key Field.
I've tried coding an If Then Else statement but it does not work, this is what I coded to try:
Private Sub Form_Load() If InstallDate = Null Then Me.AirportDiagramLoc.Visible = True Me.FirstChoiceAircraft.Visible = True Me.ProfilePicture.Visible = True Else Me.AirportDiagramLoc.Visible = False Me.FirstChoiceAircraft.Visible = False Me.ProfilePicture.Visible = False End If End Sub
I'm not sure if I have the right syntax at the beginning:
If InstallDate = Null Then
where InstallDate is the Field name and I'm trying to show it as "empty" or "Null". I thought that it would work but all it does is as if there is no If Then Else and it just works as the original top code.
Kevin Robertson 15 months ago
Use If IsNull(InstallDate) Then
Do you only need the code to run when the Form Loads?
Does it also need to run when you navigate through the records?
See: On Current
Giovanni MirandaOP 15 months ago
I've tried that as well and, and it doesn't show the Fields when the Form is Open. I got the True and False turned around it should be that when there is a Value in the IntallDate Field then the Fields are not visible, hence IsNull = True so I switched those around. But, it does not show the Fields even when there is no Value in InstallDate. This is the Code now, and yes it needs to follow from Record to Record as if for some reason the Value in InstallDate was deleted then the Fields would not be seen:
Private Sub Form_Load()
If IsNull(InstallDate) Then
Me.AirportDiagramLoc.Visible = True
Me.FirstChoiceAircraft.Visible = True
Me.ProfilePicture.Visible = True
Else
Me.AirportDiagramLoc.Visible = False
Me.FirstChoiceAircraft.Visible = False
Me.ProfilePicture.Visible = False
End If
End Sub
Thanks for your help Kevin.
Kevin Robertson 15 months ago
Try also checking for an empty string (this is different from Null).
If IsNull(InstallDate) Or InstallDate = "" Then
Since you need this to run when you move from record to record use the On Current event.
Also note: you don't need Me. throughout your code. See Bang! v Dot.
Giovanni MirandaOP 15 months ago
I've tried that as well also, but...I also have tried putting it inside the On Current event and still not working.
Giovanni MirandaOP 15 months ago
Kevin,
I've changed the Field to another Field Name just to see if there were any conflicts with any other code. Could another Event Procedure be causing it not to work? I changed my code to this for a Field called AirportCode:
'Original Code which works
Private Sub IATA_or_ICAO_Code_Click()
AirportDiagramLoc.Visible = False
FirstChoiceAircraft.Visible = False
ProfilePicture.Visible = False
End Sub
So, now my code looks like this:
If AirportCode = "" Then
AirportDiagramLoc.Visible = True
FirstChoiceAircraft.Visible = True
ProfilePicture.Visible = True
Else
AirportDiagramLoc.Visible = False
FirstChoiceAircraft.Visible = False
ProfilePicture.Visible = False
End If
Could the "FieldName.Visible = " be the wrong syntax to use in this case? And, if it possibley is what would be the correct syntax?
I took your advice and took a look at Bang! v Dot so I took the Me. out since it is on the same Form anyway, thanks for that.
Giovanni MirandaOP 15 months ago
Sorry,
IATA_or_ICAO_Code was changed to AirportCode...
Sorry, only students may add comments.
Click here for more
information on how you can set up an account.
If you are a Visitor, go ahead and post your reply as a
new comment, and we'll move it here for you
once it's approved. Be sure to use the same name and email address.
This thread is now CLOSED. If you wish to comment, start a NEW discussion in
TechHelp.
The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.