473,563 Members | 2,735 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

declaring global variables

3 New Member
I just read an older post that described declaring global variables. I tried this but I'm getting an error and the text stays red.
What am I doing wrong? This code is behind a form.
Thanks.

Option Compare Database

Global theDate As String

Function DetermineDate()
thedate = InputBox("Enter Volume Date YYYYMM")
mymonth = Right(thedate, 2)
appdate = MonthName(mymon th)
appyear = Left(thedate, 4)
End Function

Private Sub Command10_Click ()
DoCmd.OpenRepor t "Report - Table7", acViewPreview
End Sub
Nov 15 '06 #1
2 3762
nico5038
3,080 Recognized Expert Specialist
First you need to move the code into a Module, else it's scope will be limited to the form/report it's placed behind.

Option Compare Database
Option Explicit

Public theDate As String

Function GetDate() as String
GetDate = theDate
End Function

The above code in a module will allow you to use theDate even in a query like:

select * from tblX where VolumeDate = GetDate

You can use your from your code:
thedate = InputBox("Enter Volume Date YYYYMM: ")

This will fill the string and the GetDate() function will return the filled value.

Finally I wouls use Tools/Options to check the option that variables need to be defined. This will give the "Option Explicit" and warn you when using a not declared variable.

Getting the idea ?

Nic;o)
Nov 15 '06 #2
PEB
1,418 Recognized Expert Top Contributor
You can't declare Global variables in From or report module!

Only in the part MODULES you create a module and you define your global variable!!!!

Also don't do the mistake to have the same name as global variable and as sub or function name as Nico suggested.. It' wonna't work!

If your declaration is placed at place your code seems correct!
Nov 18 '06 #3

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

Similar topics

2
53860
by: ross.oneill | last post by:
Hi, I am having trouble with a simple task of declaring a variable. Is this possible? Here is what I want to do. DECLARE start_date date; DECLARE end_date date; SET start_date = '2005-01-01'
1
2416
by: ColinWard | last post by:
Hi guys. I have a question about declaring variables. I do a lot of re-querying of controls in my database and I use the Set statement with a variable set to the name of the control to tell the program which control to requery. This makes it easy to requery controls on a different form. However, up until today, I was dimming a new local...
4
6288
by: Lucy | last post by:
In the Declarations section of a form's code module, what is the difference between the following: Dim Flag As Boolean Public Flag As Boolean Private Flag As Boolean Thanks!
10
2588
by: athanasios.silis | last post by:
Hello everyone, i am attempting to make a structure #include "globalVars.h" struct myStruct{ int offset; unsigned char uChars; } saveVars, getVars;
3
2252
by: jbeteta | last post by:
Hello, I have a problem declaring variables. I need to create an object oRpte as ReportClass on WebForm1.aspx and be able to use its value on WebForm2.aspx. For declaring the property oRpte() on WebForm1.aspx, I use "Public Property" and I declare variable _oRpte as Friend Shared. That's my problem. If I don't declare _oRpte as Friend...
2
2052
by: TARUN | last post by:
I have a question about declaring the Global.ascx: In VS.NET I create a Solution, and there are 4 projects under it. They are put under 4 folders, but web pages would be called across the 4 projects. For example, web page Page1 in Project1 will redirect to web page Page2 in Project2 which will further redirect to Page3 in project3 and Page4...
8
7499
by: SM | last post by:
I've always wonder if there is diference when declaring and initializing a varible inside/outside a loop. What's a better practice? Declaring and initializing variables inside a loop routine, like this: for(var i=0; i<list; i++) { var name = list; }
2
1664
by: MLH | last post by:
I'm wondering about Public VS Global kewords that can be used in procedures inside global modules saved/viewd in the modules tab of the database window. Is it pretty much the same thing to use one or the other when declaring a global variable? If not, what is (are) the major difference(s) ?
4
4345
by: Sister Ray | last post by:
I've searched for a way to this in a lot of forums. Haven't found a solution for this, however I've found a work around. Declaring a public object and then adding the variables i want as members of thta object, like this <script> function myobject(){} var a = new myobject();
0
7659
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7882
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8103
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7634
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7945
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6244
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5481
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3634
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1194
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.