Dim variables outside of Sub top of form code page

stoka

Getting Better
Local time
Today, 13:32
Joined
Jan 22, 2007
Messages
23
I want to change the background color of each control as it receives focus to a custom color i have created, given the number 16775639. I thought I could do a Dim statement at the top of the form code page, and do an assignment such as:

Dim colSpecial as Integer
colSpecial = 16775639

However, whenever I do it, my intellisense stops working which generally is an indication of bad code. If i remove the colSpecial=16775639 it starts working again. So it accepts the Dim statement but not any assignement of value to that variable. I tried As Long, As Variant etc and received the same result. I even tried the assignement colSpecial = 5 when it was defined as an Integer -- same result.

Do I need to do something other than a Dim statement ...?
 
On the Got_focus event

Me.txtbox.BackColor = "16775639"

On the lost_focus event

Me.txtbox.BackColor = "16777215"
 
thanks. yes i defaulted to that method. i guess my general question is how do you create some variable outside on a Sub so that many Subs on that form code page can have access to it? Doing it as a Dim statement appears to not work, at least it causes my Intellisense to stop working whiich is an indication of bad code.
 
Try dimming it as a string? hence the quotes
And do you have the option explicit at the top?
 
Place the following in a module...
Code:
Public colSpecial as Double ' Edit: Good point SJ

Function GetcolSpecial ()
colSpecial = 16775639
GetcolSpecial = colSpecial
End Function

Any time you need to get the value, simply call the function GetcolSpecial() from within your code.
 
Last edited:
stoka said:
Dim colSpecial as Integer
colSpecial = 16775639

There is no way an Integer variable can hold a value of that size. Refer to the Access help files for a definition (and understanding) of the different data types.
 
It sounds like stoka wanted to set a constant value, not a variable. You almost had it, stoka. Instead of DIM, use the CONST at the top of the sub, like this:

Global Const colSpecial = 16775639

Then colSpecial will always equal 16775639 wherever you access it from.
 
As the Scotsman said, an Integer can't hold a value of 16775639! A Long would have, though!

Integer max = 32767
Long max = 2147483,647
 

Users who are viewing this thread

Back
Top Bottom