By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
462,881 Members | 711 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 462,881 IT Pros & Developers. It's quick & easy.

How to declare a global integer in VBA?

P: 27
I wrote a function in VBA which is called from an SQL proccess.
Some of the iterations of the function don't work properly so I'm trying to fix these conditions.
The bottom line is, I'm trying to compare an integer from one iteration of the function to the following one, but whenever the function gets called again it erases the integer.

Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunSQL "UPDATE TableName_
  2.  SET TableName.Time = RoundSeconds(TableName.Time)"
  5. Public Function RoundSeconds(varTime As Variant)
  6. .
  7. .
  8. .
  9. End Function
How can I save data from within the function to compare in the next iteration?

Thanks in advance,
Jun 6 '10 #1
Share this Question
Share on Google+
4 Replies

Expert 5K+
P: 8,745
  1. Declare the Variable as Static within the Function whereby it will retain its Value between successive Calls, as in:
    Expand|Select|Wrap|Line Numbers
    1. Static sintYaDaYaDa As Integer
  2. Declare the Variable as Public within a Standard Code Module, in which case it will retain its Value until the Application Terminates, as in:
    Expand|Select|Wrap|Line Numbers
    1. Public gintYaDaYaDa As Integer
Jun 6 '10 #2

P: 27
Thank you,
You helped me a lot
Jun 9 '10 #3

P: 55

Good Answer

Thank You...

Jun 9 '10 #4

Expert 5K+
P: 8,745
You are quite welcome.
Jun 9 '10 #5

Post your reply

Sign in to post your reply or Sign up for a free account.