Hide field if preceding field is empty

  • Thread starter Thread starter gavin
  • Start date Start date
G

gavin

I have a database of names and addresses and I only want the Title field to
appear on the data input form if there is a value in the Lastname field for
that record. I have been trying out a few variations based on:


Private Sub Form_AfterUpdate()



If Me.Lastname.Value = Isblank Then
Me.Title.Visible = True
Else
Me.Title.Visible = False
End If

End Sub

but it isn't working - at least I am trying though!


Can anyone help?



Regards
 
I would use...


Private Sub Form_Current() ' checks each time you move to a new
record

If Me.Lastname = "" Then
Me.Title.Visible = False
Else
Me.Title.Visible = True
End If

End Sub





I have a database of names and addresses and I only want the Title field to
appear on the data input form if there is a value in the Lastname field for
that record. I have been trying out a few variations based on:


Private Sub Form_AfterUpdate()



If Me.Lastname.Value = Isblank Then
Me.Title.Visible = True
Else
Me.Title.Visible = False
End If

End Sub

but it isn't working - at least I am trying though!


Can anyone help?



Regards
 
I have copied and pasted this code but it isn't working. The field names are
correct and I am not getting any error messages. Any idea what I'm doing
wrong?



Regards,




Gavin
 
You might try testing for null instead of "". Other than that, I can't see
any problem. Unfortunately the code that I have in my database for a
similar task is based on whether or not a particular value is stores in a
field, not simply if it contains any data.

Rick

I have copied and pasted this code but it isn't working. The field names are
correct and I am not getting any error messages. Any idea what I'm doing
wrong?



Regards,




Gavin
 
You might try these two - use BOTH:
1.) Private Sub Form_BeforeUpdate()
If IsNull(Me![Lastname]) Or Me![LastName] = "" Then
Me![Title].Visible = False 'if NO last name, then Title =
invisible
Else
Me![Title].Visible = True 'if last name entered, then
Title = visible
End If
End Sub

2.) Private Sub Form_Current() 'when move to another record
If IsNull(Me![Lastname]) Or Me![LastName] = "" Then
Me![Title].Visible = False 'if NO last name, then Title =
invisible
Else
Me![Title].Visible = True 'if last name entered, then
Title = visible
End If
End Sub

You might also add:
3.) Private Sub Form_Open(Cancel As Integer)
If IsNull(Me![Lastname]) Or Me![LastName] = "" Then
Me![Title].Visible = False 'if NO last name, then
Title = invisible
Else
Me![Title].Visible = True 'if last name entered,
then Title = visible
End If
End Sub
========================================
OR you could create ONE procedure, then call it when the above 3 events
happen.
---Phil Szlyk
 
Back
Top