How to use global variables in VBA?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Satsulima
    New Member
    • Nov 2014
    • 3

    How to use global variables in VBA?

    Hello, trying to implement a global variable iTable that I can increment/decrement and use its value anytime needed.

    1. globalvariables module:
    Code:
    Global iTable As Integer
    2. One of my subs that change its value:
    Code:
    Private Sub txtProduct1_Enter()
        iTable = 3
    End Sub
    3. Sub where I call it with a Select Case
    Code:
    Private Sub populateTxtOnEnter(ByVal copy As String, ByVal iTable As Integer)
        Select Case iTable
        Case 1
            MsgBox "ERROR"
            txtClient.Value = copy
            textTicket.SetFocus
        Case 2
            textTicket.Value = copy
            txtProduct1.SetFocus
        Case 3
            txtProduct1.Value = copy
            'txtSize1.SetFocus
        Case 4
            txtSize1.Value = copy
            txtQuantity1.SetFocus
        End Select   
    End Sub

    Now, altough I enter txtProduct1 TextBox, and my iTable is changed to 3, when the code reachs the Select Case, it always goes Case 1 and displays "ERROR" MsgBox that I created. I ask you why?

    I tried a MsgBox on txtProduct1_Ent er and it gave me iTable = 3.
    Last edited by Satsulima; Nov 19 '14, 10:34 AM. Reason: Better design
  • Satsulima
    New Member
    • Nov 2014
    • 3

    #2
    How can its value change back to 1? Please help

    Comment

    • Satsulima
      New Member
      • Nov 2014
      • 3

      #3
      Solved. No problems on global variables, other subs are calling one that puts iTable back on 1, hence the problem.

      Comment

      Working...