A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Setting Up & Running Reports
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Code when some fields have no data.



 
 
Thread Tools Display Modes
  #1  
Old February 18th, 2010, 05:02 PM posted to microsoft.public.access.reports
ann
external usenet poster
 
Posts: 462
Default Code when some fields have no data.

I am using Access 2002. I am creating a report and have three fields I need
to list with semicolons between them but they don't all have data in them.

They are txtPrimaryCompetency, txtSecondaryCompetency and
txtSupplementalCompetency. I've been trying to figure out how to list them
and not have the semicolon appear if one or two of them have no data. I have
tried using Not Null but can't get it to work. I tried using Len but I
couldn't get that to work either. I am a beginner to programming and am a
bit frustrated with trying to get this to work. I hope someone can help me.
Thank you in advance.
  #2  
Old February 18th, 2010, 05:58 PM posted to microsoft.public.access.reports
Afrosheen via AccessMonster.com
external usenet poster
 
Posts: 70
Default Code when some fields have no data.

Hi Ann;
This is a piece of code that I use when there is no information and a comma
separating lname & fname. It must be set up as a text box.

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
10 If Me.YourTextField = ", " Then
20 Me.YourTextField.Visible = False
30 Else
40 Me.YourTextField.Visible = True
50 End If
End Sub

Ann wrote:
I am using Access 2002. I am creating a report and have three fields I need
to list with semicolons between them but they don't all have data in them.

They are txtPrimaryCompetency, txtSecondaryCompetency and
txtSupplementalCompetency. I've been trying to figure out how to list them
and not have the semicolon appear if one or two of them have no data. I have
tried using Not Null but can't get it to work. I tried using Len but I
couldn't get that to work either. I am a beginner to programming and am a
bit frustrated with trying to get this to work. I hope someone can help me.
Thank you in advance.


--
Message posted via http://www.accessmonster.com

  #3  
Old February 18th, 2010, 06:20 PM posted to microsoft.public.access.reports
John Spencer
external usenet poster
 
Posts: 7,815
Default Code when some fields have no data.

Try this expression. It relies on the difference between the + concatenation
operator and the & concatenation operator.

Mid(("; " + txtPrimaryCompetency)
& ("; " + txtSecondaryCompetency)
& ("; " + txtSupplementalCompetency),3)

This will fail if you have zero-length strings (ZLS) in the fields instead of
null. In the case of ZLS in the fields you are going to have to use IIF to
test the length of the field and decide whether or not to add a semi-colon.

How it works
"; " + txtPrimaryCompetency
will evaluate to Null if txtPrimaryCompetency is Null

For every field that has a value you are adding a LEADING semi-colon and
space. So the MID strips off the first semi-colon and space in the resulting
concatenation.

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

Ann wrote:
I am using Access 2002. I am creating a report and have three fields I need
to list with semicolons between them but they don't all have data in them.

They are txtPrimaryCompetency, txtSecondaryCompetency and
txtSupplementalCompetency. I've been trying to figure out how to list them
and not have the semicolon appear if one or two of them have no data. I have
tried using Not Null but can't get it to work. I tried using Len but I
couldn't get that to work either. I am a beginner to programming and am a
bit frustrated with trying to get this to work. I hope someone can help me.
Thank you in advance.

  #4  
Old February 19th, 2010, 01:14 PM posted to microsoft.public.access.reports
ann
external usenet poster
 
Posts: 462
Default Code when some fields have no data.

Thank you John, that worked perfectly. I appreciate the help.

Thank you to "Afrosheen" I do the same thing with my names so I can use your
code too.

"John Spencer" wrote:

Try this expression. It relies on the difference between the + concatenation
operator and the & concatenation operator.

Mid(("; " + txtPrimaryCompetency)
& ("; " + txtSecondaryCompetency)
& ("; " + txtSupplementalCompetency),3)

This will fail if you have zero-length strings (ZLS) in the fields instead of
null. In the case of ZLS in the fields you are going to have to use IIF to
test the length of the field and decide whether or not to add a semi-colon.

How it works
"; " + txtPrimaryCompetency
will evaluate to Null if txtPrimaryCompetency is Null

For every field that has a value you are adding a LEADING semi-colon and
space. So the MID strips off the first semi-colon and space in the resulting
concatenation.

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

Ann wrote:
I am using Access 2002. I am creating a report and have three fields I need
to list with semicolons between them but they don't all have data in them.

They are txtPrimaryCompetency, txtSecondaryCompetency and
txtSupplementalCompetency. I've been trying to figure out how to list them
and not have the semicolon appear if one or two of them have no data. I have
tried using Not Null but can't get it to work. I tried using Len but I
couldn't get that to work either. I am a beginner to programming and am a
bit frustrated with trying to get this to work. I hope someone can help me.
Thank you in advance.

.

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 04:50 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.