473,394 Members | 2,090 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

declaring global variables

3
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(mymonth)
appyear = Left(thedate, 4)
End Function

Private Sub Command10_Click()
DoCmd.OpenReport "Report - Table7", acViewPreview
End Sub
Nov 15 '06 #1
2 3756
nico5038
3,080 Expert 2GB
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 Expert 1GB
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
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 =...
1
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...
4
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
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
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()...
2
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...
8
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,...
2
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...
4
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
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
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...

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.