473,497 Members | 2,158 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Declare vairable to use though form

68 New Member
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
Expand|Select|Wrap|Line Numbers
  1.  vba:
  2.   strstatus as string
  3.  
I have tried:
Expand|Select|Wrap|Line Numbers
  1. 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
  2.  
Expand|Select|Wrap|Line Numbers
  1. Option explsit
  2. 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.
  3.  
Expand|Select|Wrap|Line Numbers
  1.  public sub ok onclick()
  2.  ststatus = Dcount ....(vailid dcount statmdnt)
  3. end sub
  4.  public rec ()
  5.  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
  6.  
Thanks for helping, I hope my code snippets are enough to solve this problem.
Mar 25 '08 #1
3 1223
Stewart Ross
2,545 Recognized Expert Moderator Specialist
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
Mar 25 '08 #2
ADezii
8,834 Recognized Expert Expert
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
Expand|Select|Wrap|Line Numbers
  1.  vba:
  2.   strstatus as string
  3.  
I have tried:
Expand|Select|Wrap|Line Numbers
  1. 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
  2.  
Expand|Select|Wrap|Line Numbers
  1. Option explsit
  2. 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.
  3.  
Expand|Select|Wrap|Line Numbers
  1.  public sub ok onclick()
  2.  ststatus = Dcount ....(vailid dcount statmdnt)
  3. end sub
  4.  public rec ()
  5.  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
  6.  
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:
Expand|Select|Wrap|Line Numbers
  1. Private variablename As Data Type
Note: Do not declare a Variable as Public under the previous conditions.
Mar 25 '08 #3
Trevor2007
68 New Member
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.
Mar 29 '08 #4

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

Similar topics

1
2975
by: lawrence | last post by:
I'm trying to read up on the rfc's that govern form inputs. Much of what I'm reading is stuff I didn't know before and some of it is alarming. This one left with me questions: ...
6
19043
by: rick | last post by:
Noob problem. I prefer to keep all my scripts in an external '.js' file. I am currently loading the external '.js' file from the header. Problem is I would like to declare a global variable in the...
4
6118
by: Random Task | last post by:
How do i run exec and catch stdio and stderr in a local string vairable (not a file) ... Thanks very very much, Jim
8
1946
by: Johm | last post by:
In my codes i am often referring to one and the same controls.Is it possible to declare these controls only once and then insert them in all my functions and subs? For example, i am often...
8
14460
by: John Dann | last post by:
Trying to declare a structure that will contain a couple of fixed-size arrays. I'm trying eg: Structure IndexRecord Dim testarray(16) as Byte etc End Structure But vb.net is refusing to let...
3
4921
by: Altman | last post by:
I am having problems with Declaring a function from a dll. I had it work in VB 6 but I can't get it to work in VB.net. This was the call in VB6 Public Declare Function MBTConnect Lib "MBT" (ByVal...
23
3811
by: mark.moore | last post by:
I know this has been asked before, but I just can't find the answer in the sea of hits... How do you forward declare a class that is *not* paramaterized, but is based on a template class? ...
0
8289
by: roamnet | last post by:
hi i created database file with .mdf extention ,sql server as a source and use grid view to display data there're no problem in data retrieve and display,but i want to edit it or insert new...
1
3868
by: yu83thang | last post by:
Hi, May I know how to declare a Class in C++ window application form? Below is my code and error as shown below as well. here is my class declaration: ref class CLoadObj { public:
0
7121
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7162
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6881
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7375
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5456
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4899
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4584
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.