If Then Else Statement not working with Event Proceedure Code in A

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am new to this forum and pretty new to VB code. I have not done much with
it in the past and what I do is very simple. I am having a problem getting an
If Then Else statement to run. In an Access database I would like a line to
display IF a number is greater than another number ELSE I do not want it to
display anything. Each field is setup in the Access Table as a Numeric
Datatype with a field size of Long Integer. When I execute the code it always
evaluates to True despite the value in VOLSpace. For the life of me I can't
figure out why. What am I doing wrong? Any help would be greatly appreciated.
Below is my code. (Did I mention it is very simple code?)

Private Sub VOLSpacetxt_AfterUpdate()

If VOLSpace < 85 Then
VOLSpacemsg.ControlSource = "='Increase the size of the VOL1 volume.'"
VOLSpacemsg.FontBold = True
VOLSpacemsg.ForeColor = vbRed
Else
VOLSpacemsg.ControlSource = "=' '"

End If
End Sub
 
I might be reading your message wrong. However,
the code you display says if VOLSpace is less than 85 display a line.
In your explanation you said you wanted to chack that a number is greater
than another number.

And if that is not the situation may I also be so bold to assume that
VOLSpacemsg is a text box? If so rather than changing the control Source why
not just change the .text value? Like:

Private Sub VOLSpacetxt_AfterUpdate()

If VOLSpace > 85 Then
VOLSpacemsg.Text = "Increase the size of the VOL1 volume."
VOLSpacemsg.FontBold = True
VOLSpacemsg.ForeColor = vbRed
Else
VOLSpacemsg.Text = ""
End If

End Sub


-SPARKER
 
Yes, VOLSpacemsg is a text box. I am not a pro in either VB or Access so
bare with me. I tried your suggestion and it didn't work. From what I can
tell there is no Text value property for a text box. The way to add text to
a text box is in the control source.
 
Hmm... I am wondering what references you have set. This is something
important you will need now and in the future if you want to check the
references:

Writing code you will need to learn to add references to do various things
like to work with all of the Outlook objects for email or Word objects or
even writing code to manipulate Excel Spreadsheets.

While you have a module open in the Access database click on
Tools then
References then
Scroll Down until you find the references you want. In this case I am
wondering if you have these set:

Visual Basic for Applications
Microsoft Access 9.0 Object Library

Those are two of the most basic references that I have set in most all of my
databases by default and I add others ass needed like for Outlook, Excel
etc...

These are in almost everything I do as well:

OLE Automation
Microsoft ActiveX Data Objects 2.1 Library
Microsoft DAO 3.6 Object Library

These are some of the most basic references that I have set in most all of
my databases by default and I add others ass needed like for Outlook, Excel
etc...

Can you look to see what you have set for references and I will continue to
try and help you.
 
Yes. All of those References were already set. They must have been set by
default because I know I didn't manually go in there and make any selections.
I am using Access 2003 SP1. I don't know if that makes any difference. I
was able to get this code to work on a different field (on the same form in
the same db) but I can't get it to work on any other fields. I really
appreciate your help with this. I would also be willing to send a copy of
the database I am working on. It is nothing very special or important. I
would just like to start using access more and I would also like to learn
more vb.
 
Excellent! Do you see my name in blue at the top of this response? If you
click on it it should reveal my profile along with my email. It is
SpamFreePlease@[email protected]@SpamFreePlease

Right there in the middle but obviously without the two SpamFreePlease 's
and the two extra @ symbols removed.

If you post your email on the web these days without hiding it a little you
will get spammed to death.

Anyway, yes that would be great. If you want to send it across I would be
happy to take a look at it. Do you have a compression tool like winzip to zip
it up with? I do not know if you are familiar with a tool of this nature,but
it compresses the size of your database,or any other file you stick in it for
that matter, significantly.

I will look through and see if I can figure out what is going on.

- SPARKER
 
Will you try creating your code for the AfterUpdate event of the Volspace
object?
Secondly, verify that the VoLSpace field is of number data type. So it may
read:

Private Sub VOLSpace_AfterUpdate()
If VOLSpace < 85 Then
VolSpacemsg = "Increase the size of the VOL1 volume"
Else
VolSpacemsg = ""
End If
End Sub
 
Back
Top