PC Review


Reply
Thread Tools Rate Thread

Defineing variables

 
 
Mike
Guest
Posts: n/a
 
      13th Sep 2003
I inherited a very complex database from another developer
who is no longer with my company. On a specific report,
he had it so that if a specific field does not contain any
data, it would not print the label, but if it did contain
data, it would print the label and the information it
contains. The Control Source for the field looks as
follows.

="Voice : " & [Voice]

There is some VBA attributed to the report with code that
looks like:

If IsNull(Voice.Value) Then
LblVoice.Visible = False
Else
LblVoice.Visible = True
End If

If IsNull(Fax.Value) Then
LblFax.Visible = False
Else
LblFax.Visible = True
End If

This is telling the report that if the value is null, do
not print the label "Voice", but if there is a value, to
print "Voice: 703-555-1234"

I am trying to do this for other fields (e.g. POCName) on
the report using the same process. I try to replicate the
code to my own use, to look like for example:

If IsNull(POCName.Value) Then
LblPOCName.Visible = False
Else
LblPOCName.Visible = True
End If

However, I get the error code "Compile error: Variable not
defined" and the "POCName" is highlighted. I am not very
proficient with VBA, but where do I define the variable?
Using the "Find" function, I hunted through the code of
the entire project for where the original developer may
have defined the variables for "Voice" or "Fax", but I can
not find them anywhere. I assume there is a a Dim
statement somewhere, but where?!

Any assistance would be appreciated.

m.

 
Reply With Quote
 
 
 
 
Albert D. Kallal
Guest
Posts: n/a
 
      14th Sep 2003
> However, I get the error code "Compile error: Variable not
> defined" and the "POCName" is highlighted. I am not very
> proficient with VBA, but where do I define the variable?



You don't define the variable. The code is supposed to use the name of the
text box, and the name of the label that you *placed* on the form.

So, no, you don't have to define the variable, but you must use either an
existing variable, or the name of a control on the form. (in your case, you
need to use the same name as what the text box control is named on the
form).

You probably should not use the default name that ms-access gives (like
text22 etc). so, highlight the text box in design mode, and you can thus see
the name of the control in the properties tab.


--
Albert D. Kallal (MVP)
Edmonton, Alberta Canada
(E-Mail Removed)
http://www.attcanada.net/~kallal.msn


 
Reply With Quote
 
tina
Guest
Posts: n/a
 
      14th Sep 2003
are you sure the original developer used variables?
it looks like "Voice" is a field in the report's
RecordSource. it looks like "LblVoice" is the name of a
control on the report. my guess is the same goes for "Fax"
and "LblFax".
so, is there a field in the RecordSource called "POCName"?
and is there a control on the report called "LblPOCName"?
if not, try changing your code to reference the actual
field's name and the actual control's name that you're
trying to manipulate.


>-----Original Message-----
>I inherited a very complex database from another

developer
>who is no longer with my company. On a specific report,
>he had it so that if a specific field does not contain

any
>data, it would not print the label, but if it did contain
>data, it would print the label and the information it
>contains. The Control Source for the field looks as
>follows.
>
>="Voice : " & [Voice]
>
>There is some VBA attributed to the report with code that
>looks like:
>
>If IsNull(Voice.Value) Then
>LblVoice.Visible = False
>Else
>LblVoice.Visible = True
>End If
>
>If IsNull(Fax.Value) Then
>LblFax.Visible = False
>Else
>LblFax.Visible = True
>End If
>
>This is telling the report that if the value is null, do
>not print the label "Voice", but if there is a value, to
>print "Voice: 703-555-1234"
>
>I am trying to do this for other fields (e.g. POCName) on
>the report using the same process. I try to replicate

the
>code to my own use, to look like for example:
>
>If IsNull(POCName.Value) Then
>LblPOCName.Visible = False
>Else
>LblPOCName.Visible = True
>End If
>
>However, I get the error code "Compile error: Variable

not
>defined" and the "POCName" is highlighted. I am not very
>proficient with VBA, but where do I define the variable?
>Using the "Find" function, I hunted through the code of
>the entire project for where the original developer may
>have defined the variables for "Voice" or "Fax", but I

can
>not find them anywhere. I assume there is a a Dim
>statement somewhere, but where?!
>
>Any assistance would be appreciated.
>
>m.
>
>.
>

 
Reply With Quote
 
Marshall Barton
Guest
Posts: n/a
 
      14th Sep 2003
Mike wrote:

>I inherited a very complex database from another developer
>who is no longer with my company. On a specific report,
>he had it so that if a specific field does not contain any
>data, it would not print the label, but if it did contain
>data, it would print the label and the information it
>contains. The Control Source for the field looks as
>follows.
>
>="Voice : " & [Voice]
>
>There is some VBA attributed to the report with code that
>looks like:
>
>If IsNull(Voice.Value) Then
>LblVoice.Visible = False
>Else
>LblVoice.Visible = True
>End If
>
>If IsNull(Fax.Value) Then
>LblFax.Visible = False
>Else
>LblFax.Visible = True
>End If
>
>This is telling the report that if the value is null, do
>not print the label "Voice", but if there is a value, to
>print "Voice: 703-555-1234"
>
>I am trying to do this for other fields (e.g. POCName) on
>the report using the same process. I try to replicate the
>code to my own use, to look like for example:
>
>If IsNull(POCName.Value) Then
>LblPOCName.Visible = False
>Else
>LblPOCName.Visible = True
>End If
>
>However, I get the error code "Compile error: Variable not
>defined" and the "POCName" is highlighted. I am not very
>proficient with VBA, but where do I define the variable?
>Using the "Find" function, I hunted through the code of
>the entire project for where the original developer may
>have defined the variables for "Voice" or "Fax", but I can
>not find them anywhere. I assume there is a a Dim
>statement somewhere, but where?!


No, no such Dim statement. The giveaway is that variables
do not have a Value property. Voice will be the name of the
text box control that is bound to the Voice field in the
report's record source query. If that's confusing, it's a
good reason to give the control a different name than the
field it's bound to (I would have named the text box
txtVoice). I would then write that code:

If IsNull(Me.txtVoice.Value) Then
. . .

Using Me removes the potential ambiguity with a variable of
the same name.

Let's take this logic a little further. Since the If
condition expression, IsNull(Me.txtVoice.Value), is either
True or False, and you want to set the Visible property to
either True or False, the code for Voice could be reduced to
one line:

Me.LblVoice.Visible = Not IsNull(Me.txtVoice.Value)

Another small point you should be aware of is that if you
make a text box invisible, its attached label will also
become invisible. So, if your labels are attached to the
text box, you wouldn't need to know/change the names of the
labels too.

Me.txtVoice.Visible = Not IsNull(Me.txtVoice.Value)

This might save you a line of code when your text box has a
border you don't want to see.

--
Marsh
MVP [MS Access]
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What has priority: PATH from User variables or system variables? Sabine Elsner Windows XP Help 3 21st Oct 2008 02:42 PM
Session variables and static variables loss own contained value. neeraj Microsoft VB .NET 0 6th Sep 2006 01:33 PM
Excel Versions and defineing word.application stevenmckeon Microsoft Excel Programming 1 4th Aug 2004 03:17 AM
Re: Class public shared Variables vs. Application Variables in ASP.NET avnrao Microsoft ASP .NET 0 7th May 2004 06:28 AM
User Environment variables overriden by system env variables Bonny Windows XP Setup 0 11th Jul 2003 06:01 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:02 PM.