Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hide date textboxes on report 1

Status
Not open for further replies.
Sep 12, 2007
45
US

I am working with a SQL Server database table which has a couple of Date (datetime, null) columns (‘FirstSurveyDate’ and ‘SecondSurveyDate’) in which some date records in ‘FirstSurveyDate’ column are NULL. This table is linked to Access.

I am using a simple query to show all the records from this table in a report. In the report, there is only one Survey date field (text box) which needs to display the date the (any, first or second or both) survey was taken. If the First date is available the second date doesn’t need to be displayed. But if the first date is not available (that is, the survey was taken on the second date), the second date needs to be displayed. Second surveys are mandatory and therefore these dates are never NULL.

In the report, I have placed two text boxes (‘FirstSurveyDate’ and ‘SecondSurveyDate’)where the second box is placed over the first.

What I want to do is …… if the first survey date is NULL then second survey date should be displayed. If the first survey date is not NULL then the first survey date should be displayed but not the second.

I tried the following in both the report’s ‘On Load’ and ‘Detail – Format’ event/procedures ……

If IsNull(Me.FirstSurveyDate) then
Me.SecondSurveyDate.Visible = True
Me.FirstSurveyDate.Visible = False
Else
Me.SecondSurveyDate.Visible = False
Me.FirstSurveyDate.Visible = True
End If

But this does not have the intended effect. Both the textboxes display their content i.e. if both dates are not NULL they both get displayed which is something that shouldn’t happen.

I tried setting the ‘Can Grow’ and ‘Can Shrink’ properties of the First and Second text boxes to ‘Yes’ but that only works in the first box is not NULL and the Second is NULL.

I was wondering if ‘NULL’ in SQL Server is displayed as some invisible yet Not NULL entry in Access query output.

Please suggest a solution to this issue. Is there an alternative to using ‘IsNull’ in the above ‘If-Then’ statement to address this situation with NULL in SQL Server date field and its Access equivalent?

Thank you all for your help.



 
I think you can simply use a single text box with a control source of:

Code:
=Nz([FirstSurveyDate], [SecondSurveyDate])

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016
 

Thank you Duane.

I used a single textbox (SurveyDate) as you suggested.

I entered your code in the control source property of the textbox but I get an #size! error. I don't what it means.

I then entered it in the Detail - Format as
Me.SurveyDate =Nz([FirstSurveyDate], [SecondSurveyDate])

But the issue persists.
 
Make sure the name of the text box is not the name of a field and You don't have a user defined function named "nz"

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016
 

Thank you Duane. It worked!

I was using the ‘FirstSurveyDate’ textbox which as you pointed out was the reason for the error.

I created a new textbox ‘SurveyDate’ and used =Nz([FirstSurveyDate], [SecondSurveyDate]) as its control source.

I got a #Type! Error for records with SecondSurveyDate.

I changed the code to …… =Nz([FirstSurveyDate],(Format$([ SecondSurveyDate],"mm/dd/yyyy"))).

This cleared the error and it’s works great.

Thank you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top