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

Module/ global variable problem

P: 48
Hello again Humble helpfulls. Im having difficult with a module i have created. As its my first it was never going to be straightforward lol. But I was looking at one of the other treads and found it quite helpful about global variables but i eventually ran into difficulty..
the following code is for the click event that calls the Clicker Module
Expand|Select|Wrap|Line Numbers
  1. Private Sub Image30_Click()
  2. Dim counterx As Module
  3. Set counterx = Clicker
  4. counterx.IncrementCounter
  5.  
  6. If (counterx.GetCount > 3) Then
  7. DoCmd.OpenForm ("pcspecs2")
  8. counterx.ResetCounter
  9. Else
  10. Exit Sub
  11. End If
  12.  
Tye following is the code for my Clicker Module
Expand|Select|Wrap|Line Numbers
  1. Public count As Integer
  2.  
  3. Option Compare Database
  4.  
  5.  
  6. Public Function GetCount() As Integer
  7.     GetCount = count
  8. End Function
  9.  
  10. Public Function IncrementCounter()
  11.   count = count + 1
  12. End Function
  13.  
  14. Public Function ResetCounter()
  15. count = 0
  16. End Function
  17.  
The idea is that when the user click on an icon 3 times they will be brought to a new form. Any pointers on Module declareation and use would be apprieciated. Also i tried To initialise the count variable but it would not work. Can you not initialise a global variable or have i declared that wrong too lol.

Regards
Panteraboy
May 6 '08 #1
Share this Question
Share on Google+
2 Replies


ADezii
Expert 5K+
P: 8,634
Hello again Humble helpfulls. Im having difficult with a module i have created. As its my first it was never going to be straightforward lol. But I was looking at one of the other treads and found it quite helpful about global variables but i eventually ran into difficulty..
the following code is for the click event that calls the Clicker Module
Expand|Select|Wrap|Line Numbers
  1. Private Sub Image30_Click()
  2. Dim counterx As Module
  3. Set counterx = Clicker
  4. counterx.IncrementCounter
  5.  
  6. If (counterx.GetCount > 3) Then
  7. DoCmd.OpenForm ("pcspecs2")
  8. counterx.ResetCounter
  9. Else
  10. Exit Sub
  11. End If
  12.  
Tye following is the code for my Clicker Module
Expand|Select|Wrap|Line Numbers
  1. Public count As Integer
  2.  
  3. Option Compare Database
  4.  
  5.  
  6. Public Function GetCount() As Integer
  7.     GetCount = count
  8. End Function
  9.  
  10. Public Function IncrementCounter()
  11.   count = count + 1
  12. End Function
  13.  
  14. Public Function ResetCounter()
  15. count = 0
  16. End Function
  17.  
The idea is that when the user click on an icon 3 times they will be brought to a new form. Any pointers on Module declareation and use would be apprieciated. Also i tried To initialise the count variable but it would not work. Can you not initialise a global variable or have i declared that wrong too lol.

Regards
Panteraboy
Hello Panteraboy, I think you may want to take a different approach to this problem:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Image30_Click()
  2. 'Declaring a Variable as 'Static' enables it to retain its
  3. 'value between successive calls to this Click() Event
  4. Static intClickCount As Integer
  5.  
  6. intClickCount = intClickCount + 1
  7.  
  8. If intClickCount = 3 Then       'Image clicked 3 times
  9.   intClickCount = 0             'Reset Variable
  10.   'it's the 3rd click, so Open the Form
  11.   DoCmd.OpenForm "<Your Form Name>", YadaYadaYada...
  12. Else
  13.   'don't need this, but just an illustration to indicate
  14.   'that you take no action
  15. End If
  16. End Sub
May 6 '08 #2

P: 48
Thanks a million. I had code similar to that but my variable wasnt static. Helpfull as always
Regards
Pantera boy
May 7 '08 #3

Post your reply

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