How to write code for if field exists 
Author Message
 How to write code for if field exists

I have a report based on a query which in turn is based on a cross tab.  The
cross tab Column headings returns fields 1 through 20 only (never more, never
less).  But sometimes there is a blank and that heading does not appear.  So
when I have a text box in the report for heading 17 and 17 is presently null, I
get an error.  This makes sense because 17 is not a field.  

What can I write in the ControlSource for each text box to say if field does
not exist print null?
If I must use code, how would the code look?

Doyle60



Sun, 09 Jul 2000 03:00:00 GMT  
 How to write code for if field exists

emailed...

Trevor Dwyer

Quote:

>I have a report based on a query which in turn is based on a cross tab.
The
>cross tab Column headings returns fields 1 through 20 only (never more,
never
>less).  But sometimes there is a blank and that heading does not appear.
So
>when I have a text box in the report for heading 17 and 17 is presently
null, I
>get an error.  This makes sense because 17 is not a field.

>What can I write in the ControlSource for each text box to say if field
does
>not exist print null?
>If I must use code, how would the code look?

>Doyle60



Sun, 09 Jul 2000 03:00:00 GMT  
 How to write code for if field exists

One solution would be to use the column heading property of the crosstab
query to ensure that all the headings always appear.

Terry



Quote:
> I have a report based on a query which in turn is based on a cross tab.
The
> cross tab Column headings returns fields 1 through 20 only (never more,
never
> less).  But sometimes there is a blank and that heading does not appear.
So
> when I have a text box in the report for heading 17 and 17 is presently
null, I
> get an error.  This makes sense because 17 is not a field.  

> What can I write in the ControlSource for each text box to say if field
does
> not exist print null?
> If I must use code, how would the code look?

> Doyle60



Mon, 10 Jul 2000 03:00:00 GMT  
 How to write code for if field exists

Hey,

You did not mention which version of Access you are using, but if you are using
Access97 then look in the help file for Nz which will allow you to deal with
nulls on Reports.

HTH,
Mary

Quote:
>I have a report based on a query which in turn is based on a cross tab.  The
>cross tab Column headings returns fields 1 through 20 only (never more, never
>less).  But sometimes there is a blank and that heading does not appear.  So
>when I have a text box in the report for heading 17 and 17 is presently null,
>I
>get an error.  This makes sense because 17 is not a field.  

>What can I write in the ControlSource for each text box to say if field does
>not exist print null?
>If I must use code, how would the code look?

>Doyle60



Mon, 10 Jul 2000 03:00:00 GMT  
 How to write code for if field exists

Hi,

In addition to the column Heading property that will insure you that the
field is already included, as suggested by Terry, in a general case, you can
check if the fields name return an error or not:

    On Error Resume Next
    Dummy=rst.Fields("TheName").Name
    FieldExist = ( Err.Number <> 0 )

Hope it may help,
Vanderghast, Access MVP

Quote:

>I have a report based on a query which in turn is based on a cross tab.
The
>cross tab Column headings returns fields 1 through 20 only (never more,
never
>less).  But sometimes there is a blank and that heading does not appear.
So
>when I have a text box in the report for heading 17 and 17 is presently
null, I
>get an error.  This makes sense because 17 is not a field.

>What can I write in the ControlSource for each text box to say if field
does
>not exist print null?
>If I must use code, how would the code look?

>Doyle60



Mon, 10 Jul 2000 03:00:00 GMT  
 How to write code for if field exists

Question withdrawn.
I was able to avoid the cross tab query.
Thanks.

Doyle60



Mon, 10 Jul 2000 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Looking for some Visual Basic code if it already exist, or someone to write this code

2. How to modified existing field and add new field in existing table for Access database

3. Changing the size of an existing field through code

4. Create new field in existing table exactly like field in second table

5. Writing out VBS code with response.write()

6. Help - writing to text field / database field

7. Writing table data to an existing spreadsheet

8. Write image data as binary to append existing file

9. Problems with writing into existing Textfile

10. writing to existing text file

11. If file exists, over write or cancel?

12. File I/O - writing/inserting data to existing file

 

 
Powered by phpBB® Forum Software