Hiding Fields in Access

D

davegh7

Hi there, I am working in a form where I would like to hide a field if
it is blank/null. I'm using:

If IsNull(Forms![LeasesTable]![Term2]) Then
Forms![LeasesTable]![Term2].Visible = False
Else: Forms![LeasesTable]![Term2].Visible = True

In this case, it would only hide the field if the first record was
blank. I'll have some fields blank and some will not.
 
M

Merle Nicholson

I thought this would be a challenge to make the simplest solution. Here's one
way:

Create new query "qryTotTerm2"
SELECT Sum(IsNull([Term2]))*-1 AS Tot
FROM LeasesTable;

Create a new form based on the query. The form wizard will do a quick one
with just one field "Tot", I called it GetTerm2Nulls. So the value of
[GetTerm2Nulls]![Tot] will be the total number of records with nulls in
[Term2]. Make the form hidden.

So then
If [GetTerm2Nulls]![Tot] > 0 Then . . . visible = False
 
M

Maurice

You could also opt for this one:

(i assume this is when you browse through the records, in that case put it
behind the on_current of the form)

Forms![LeasesTable]![Term2].Visible=not isnull(Forms![LeasesTable]![Term2])

hth
 
R

Ron2006

will not work on continuous forms

But there you can use in the same place

me.term2.columnwidth = 0

This will make it invisible for most users.
 
R

Ron2006

Should perhaps be:


If IsNull(Forms![LeasesTable]![Term2]) Then
   me.term2.columnwidth = 0
else
me.term2.columnwidth = nn ' where nn is the width you
want for it.
endif
 
R

Ron2006

The above things will provide interesing changes as you go from record
to record in a continuous form.

A sometimes usuable alternative is to do conditional formating and
make the field disabled on the expression:

isnull([term2])

or

isnull([term2]) = true

and then select the last icon on the right which makes the field
disabled and not updatable.

Ron
 

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

Top