473,387 Members | 1,542 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,387 software developers and data experts.

Public Variable- Why doesnt this work?

I have declared 'db;ProgID' as a public variable in a module

I have a form with a combo box in which I choose a particular
programme and the value gets stored as dblProgID. I know this part
works correctly, because MsgBox(dblProgID) at this point displays the
correct value.

I then open a report for which the following query (saved query) is
the record source.

SELECT Programmes.*
FROM Programmes
WHERE (((Programmes.ProgID)=[dblProgID]));

But the query does not take the already set value of 'dblProgID'.
Instead, it pops up the parameter input box asking for dblProgID. Why?

I have solved my problem by building a SQL string concatenating the
value of dblProgID into it. But I would still like to know why this
happens

Sunil Korah
Nov 12 '05 #1
3 1659
my 2 loonies, try getting the value from a function

public function GetProgID()

GetProgID = ProgID
end function
then

SELECT Programmes.*
FROM Programmes
WHERE Programmes.ProgID=" & GetProgID() & ";"

John Bickmore
www.BicycleCam.com
www.Feed-Zone.com

"Sunil Korah" <hb*****@indiatimes.com> wrote in message
news:72**************************@posting.google.c om...
I have declared 'db;ProgID' as a public variable in a module

I have a form with a combo box in which I choose a particular
programme and the value gets stored as dblProgID. I know this part
works correctly, because MsgBox(dblProgID) at this point displays the
correct value.

I then open a report for which the following query (saved query) is
the record source.

SELECT Programmes.*
FROM Programmes
WHERE (((Programmes.ProgID)=[dblProgID]));

But the query does not take the already set value of 'dblProgID'.
Instead, it pops up the parameter input box asking for dblProgID. Why?

I have solved my problem by building a SQL string concatenating the
value of dblProgID into it. But I would still like to know why this
happens

Sunil Korah

Nov 12 '05 #2
On 26 Dec 2003 21:19:23 -0800 in comp.databases.ms-access,
hb*****@indiatimes.com (Sunil Korah) wrote:
I have declared 'db;ProgID' as a public variable in a module

I have a form with a combo box in which I choose a particular
programme and the value gets stored as dblProgID. I know this part
works correctly, because MsgBox(dblProgID) at this point displays the
correct value.

I then open a report for which the following query (saved query) is
the record source.

SELECT Programmes.*
FROM Programmes
WHERE (((Programmes.ProgID)=[dblProgID]));

But the query does not take the already set value of 'dblProgID'.
Instead, it pops up the parameter input box asking for dblProgID. Why?

I have solved my problem by building a SQL string concatenating the
value of dblProgID into it. But I would still like to know why this
happens


What John said + why it happens is because variables (whether private
or public/global) are exposed to VBA only, not to SQL. Functions are
exposed to VBA, SQL, macros, and controls.

--
A)bort, R)etry, I)nfluence with large hammer.
Nov 12 '05 #3
Thanks a lot. I didn't know that. I used to programme mainly in Foxpro
and switched to Access only about an year back. In Foxpro I could use
the variables in SQL and so I was continuing to try the same.

Sunil Korah

Trevor Best <bouncer@localhost> wrote in message news:<a3********************************@4ax.com>. ..
On 26 Dec 2003 21:19:23 -0800 in comp.databases.ms-access,
hb*****@indiatimes.com (Sunil Korah) wrote:
I have declared 'db;ProgID' as a public variable in a module

I have a form with a combo box in which I choose a particular
programme and the value gets stored as dblProgID. I know this part
works correctly, because MsgBox(dblProgID) at this point displays the
correct value.

I then open a report for which the following query (saved query) is
the record source.

SELECT Programmes.*
FROM Programmes
WHERE (((Programmes.ProgID)=[dblProgID]));

But the query does not take the already set value of 'dblProgID'.
Instead, it pops up the parameter input box asking for dblProgID. Why?

I have solved my problem by building a SQL string concatenating the
value of dblProgID into it. But I would still like to know why this
happens


What John said + why it happens is because variables (whether private
or public/global) are exposed to VBA only, not to SQL. Functions are
exposed to VBA, SQL, macros, and controls.

Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Banaticus Bart | last post by:
I wrote an abstract base class from which I've derived a few other classes. I'd like to create a base class array where each element is an instance of a derived object. I can create a base class...
10
by: Zap | last post by:
Widespread opinion is that public data members are evil, because if you have to change the way the data is stored in your class you have to break the code accessing it, etc. After reading this...
2
by: THY | last post by:
Hi, I am having some problem, I declare few variable in a public module and use them in the web application. But after that I found that the variable declared in public variable =...
3
by: Joe Fallon | last post by:
I have a Shared varibale in a base class and all the Shared methods in the sub-classes use it (and CHANGE it). I thought I was saving myself the "trouble" of Dimming this variable inside each...
10
by: darrel | last post by:
I'm still trying to sort out in my head the differences between public and shared when referring to declaring properties or variables. This is my understanding: shared - akin to a 'global'...
3
by: Tor Inge Rislaa | last post by:
How to use a public variable In VB.6.0 I could in the declaration part of a form declare a public variable, then assign a value to the variable, open a new form and address the variable and read...
5
by: Neil Steventon | last post by:
Hi, I am new to VB.net , well the objects concept anyway and was wondering if there were any good articles / turorials on when and why you would use certain declarations such as Private test...
9
by: Stefan De Schepper | last post by:
Should I use: Private m_Name As String Public Property Name() As String Get Return m_Name End Get Set(ByVal Value As String) m_Name = Value
11
by: dgk | last post by:
If I have a class with a public variable, isn't this the same as a private variable with a property? ie, isn't this: Public Class MyTest Public MyVar as String End Class the same as this: ...
10
by: timber910 | last post by:
OK, I've searched all over and used the help on the VBA editor. Helped a little but I'm not getting close enough to see where I'm going wrong. I need a public variable that I will be able to use...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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...

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.