Declare vairable to use though form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Trevor2007
    New Member
    • Feb 2008
    • 68

    Declare vairable to use though form

    I am having trouble declairing a variable so that I call get it's value in one event but then call to that variable to retrieve the value in other events (all on the same form.
    The variable I am trying to declair is
    Code:
     vba:
      strstatus as string
    I have tried:
    Code:
    public ststatus as string ' the counter is always 1 even though a Dcount is performed from the table, and the values that are sent to the table via inert query are never sent to the table
    Code:
    Option explsit
    Dim ststatus as string '  ststatus only holds a value onclick event, in other events ststaus is 0 or null (and it was never set to that value, I tested with textboxes to varify that a value should be present.
    Code:
     public sub ok onclick()
     ststatus = Dcount ....(vailid dcount statmdnt)
    end sub
     public rec ()
     If ststmtus is >3 then msgbox "count is" & chr$(32) & ststatus ' and the count is always 0 , even though the value  add up to definetly more then 0 in the table
    Thanks for helping, I hope my code snippets are enough to solve this problem.
  • Stewart Ross
    Recognized Expert Moderator Specialist
    • Feb 2008
    • 2545

    #2
    Hi. There are spelling errors in the names listed for your global variable and some of the code which makes proper comment on what you have tried impossible, as the errors shown may just be because you typed the line incorrectly here but not in your code (option explsit instead of Option Explicit for instance - compiler would simply not accept explsit as a valid argument).

    If your public (global) variable is declared in a public code module (not in a form module or similar) it can be set and read by code in any code module in your database, assuming that the references to it are correctly spelled. If you are sure you are referring to it correctly I would suggest that you set breakpoints in the VBE editor and step through the lines of code that set or refer to your global. If you hover your mouse over the name of a variable within code stopped by breakpoint you will see the live values for all the variables and object references.
    -Stewart

    Comment

    • ADezii
      Recognized Expert Expert
      • Apr 2006
      • 8834

      #3
      Originally posted by Trevor2007
      I am having trouble declairing a variable so that I call get it's value in one event but then call to that variable to retrieve the value in other events (all on the same form.
      The variable I am trying to declair is
      Code:
       vba:
        strstatus as string
      I have tried:
      Code:
      public ststatus as string ' the counter is always 1 even though a Dcount is performed from the table, and the values that are sent to the table via inert query are never sent to the table
      Code:
      Option explsit
      Dim ststatus as string '  ststatus only holds a value onclick event, in other events ststaus is 0 or null (and it was never set to that value, I tested with textboxes to varify that a value should be present.
      Code:
       public sub ok onclick()
       ststatus = Dcount ....(vailid dcount statmdnt)
      end sub
       public rec ()
       If ststmtus is >3 then msgbox "count is" & chr$(32) & ststatus ' and the count is always 0 , even though the value  add up to definetly more then 0 in the table
      Thanks for helping, I hope my code snippets are enough to solve this problem.
      You want to limit the scope of your Variable Declarations to the tightest scope possible without losing functionality. If a Variable is be used only within the context of a single Form, then by all means, Declare it in the General Declarations Section of your Form as follows:
      [CODE=vb]
      Private variablename As Data Type[/CODE]Note: Do not declare a Variable as Public under the previous conditions.

      Comment

      • Trevor2007
        New Member
        • Feb 2008
        • 68

        #4
        Ok, I solved this but not by declareing variable I traped arrors and used them to my advantage, since I wasn't having anyluck with using a call to a string that contained a value from other events within the save form.

        Comment

        Working...