PC Review


Reply
Thread Tools Rate Thread

How do i make a constant for query use?

 
 
=?Utf-8?B?SGF3a2lfaWNl?=
Guest
Posts: n/a
 
      26th Jan 2007
Ok this is driving me nutz, all I am trying to do is create a Constant which
i can easy change in access and be able to use it in Querys to calculate
totals

can someone plse tell me how to make a Constant for my database and the
"expression" i use to look it up

seeing as microsoft cant put this simple information anywhere in there help
or website
 
Reply With Quote
 
 
 
 
Rick Brandt
Guest
Posts: n/a
 
      26th Jan 2007
Hawki_ice wrote:
> Ok this is driving me nutz, all I am trying to do is create a
> Constant which i can easy change in access and be able to use it in
> Querys to calculate totals
>
> can someone plse tell me how to make a Constant for my database and
> the "expression" i use to look it up
>
> seeing as microsoft cant put this simple information anywhere in
> there help or website


To be used in a query you need a user defined function that returns the value fo
the constant...

Public Const MyConstant = "SomeValue"

Function GetMyConstant() As String
GetMyConstant = MyConstant
End Function

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com


 
Reply With Quote
 
=?Utf-8?B?SGF3a2lfaWNl?=
Guest
Posts: n/a
 
      26th Jan 2007
Gah thanks so mush, i knew it was simple just the stupid help dosent give me
any of that information just "you can do it" but not HOW to actualy do it

Thanks so much

"Rick Brandt" wrote:

> Hawki_ice wrote:
> > Ok this is driving me nutz, all I am trying to do is create a
> > Constant which i can easy change in access and be able to use it in
> > Querys to calculate totals
> >
> > can someone plse tell me how to make a Constant for my database and
> > the "expression" i use to look it up
> >
> > seeing as microsoft cant put this simple information anywhere in
> > there help or website

>
> To be used in a query you need a user defined function that returns the value fo
> the constant...
>
> Public Const MyConstant = "SomeValue"
>
> Function GetMyConstant() As String
> GetMyConstant = MyConstant
> End Function
>
> --
> Rick Brandt, Microsoft Access MVP
> Email (as appropriate) to...
> RBrandt at Hunter dot com
>
>
>

 
Reply With Quote
 
strive4peace
Guest
Posts: n/a
 
      26th Jan 2007
You can reference a function in, for instance, the Field cell of a query
like this:

Field --> MyColumn: GetMyConstant() * [fieldname]

~~~

How to Create a General Module

1. from the database window, click on the Module tab
2. click on the NEW command button
3. type (or paste) the code in

once the code is in the module sheet, do
Debug,Compile from the menu

if there are no syntax/reference errors, nothing will appear to happen
-- this is good


Warm Regards,
Crystal
*
(: have an awesome day
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*



Hawki_ice wrote:
> Gah thanks so mush, i knew it was simple just the stupid help dosent give me
> any of that information just "you can do it" but not HOW to actualy do it
>
> Thanks so much
>
> "Rick Brandt" wrote:
>
>> Hawki_ice wrote:
>>> Ok this is driving me nutz, all I am trying to do is create a
>>> Constant which i can easy change in access and be able to use it in
>>> Querys to calculate totals
>>>
>>> can someone plse tell me how to make a Constant for my database and
>>> the "expression" i use to look it up
>>>
>>> seeing as microsoft cant put this simple information anywhere in
>>> there help or website

>> To be used in a query you need a user defined function that returns the value fo
>> the constant...
>>
>> Public Const MyConstant = "SomeValue"
>>
>> Function GetMyConstant() As String
>> GetMyConstant = MyConstant
>> End Function
>>
>> --
>> Rick Brandt, Microsoft Access MVP
>> Email (as appropriate) to...
>> RBrandt at Hunter dot com
>>
>>
>>

 
Reply With Quote
 
Douglas J. Steele
Guest
Posts: n/a
 
      26th Jan 2007
An alternative approach to what Rick and Crystal have suggested is to have a
form that's constant open contain the value in a control, and have the
queries refer to that control. (the Switchboard form makes a good choice if
you have one)

You refer to a control on an opened form as Forms!NameOfForm!NameOfControl

That would make it easier to change what value's used (although it might
also increase the possibility that it's changed incorrectly)

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Hawki_ice" <(E-Mail Removed)> wrote in message
news:2EFDA325-D290-4F6C-BB4E-(E-Mail Removed)...
> Ok this is driving me nutz, all I am trying to do is create a Constant
> which
> i can easy change in access and be able to use it in Querys to calculate
> totals
>
> can someone plse tell me how to make a Constant for my database and the
> "expression" i use to look it up
>
> seeing as microsoft cant put this simple information anywhere in there
> help
> or website



 
Reply With Quote
 
(PeteCresswell)
Guest
Posts: n/a
 
      26th Jan 2007
Per Douglas J. Steele:
>An alternative approach to what Rick and Crystal have suggested is to have a
>form that's constant open contain the value in a control, and have the
>queries refer to that control. (the Switchboard form makes a good choice if
>you have one)
>
>You refer to a control on an opened form as Forms!NameOfForm!NameOfControl
>
>That would make it easier to change what value's used (although it might
>also increase the possibility that it's changed incorrectly)


Would it also be faster than having the query call a function for every row?
--
PeteCresswell
 
Reply With Quote
 
Douglas J. Steele
Guest
Posts: n/a
 
      26th Jan 2007
"(PeteCresswell)" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Per Douglas J. Steele:
>>An alternative approach to what Rick and Crystal have suggested is to have
>>a
>>form that's constant open contain the value in a control, and have the
>>queries refer to that control. (the Switchboard form makes a good choice
>>if
>>you have one)
>>
>>You refer to a control on an opened form as Forms!NameOfForm!NameOfControl
>>
>>That would make it easier to change what value's used (although it might
>>also increase the possibility that it's changed incorrectly)

>
> Would it also be faster than having the query call a function for every
> row?


I'm reluctant to say yes or no without testing.

It certainly depends on how the values are being used: if, for example,
they're only referenced in the Where clause, the function would only be
called once.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)



 
Reply With Quote
 
strive4peace
Guest
Posts: n/a
 
      26th Jan 2007
The function will only be called once for the query anyway -- because no
parameter is passed... FORCING a function to evaluate each time must be
done by passing a field, even if it is not needed.

Warm Regards,
Crystal
*
(: have an awesome day
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*



Douglas J. Steele wrote:
> "(PeteCresswell)" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Per Douglas J. Steele:
>>> An alternative approach to what Rick and Crystal have suggested is to have
>>> a
>>> form that's constant open contain the value in a control, and have the
>>> queries refer to that control. (the Switchboard form makes a good choice
>>> if
>>> you have one)
>>>
>>> You refer to a control on an opened form as Forms!NameOfForm!NameOfControl
>>>
>>> That would make it easier to change what value's used (although it might
>>> also increase the possibility that it's changed incorrectly)

>> Would it also be faster than having the query call a function for every
>> row?

>
> I'm reluctant to say yes or no without testing.
>
> It certainly depends on how the values are being used: if, for example,
> they're only referenced in the Where clause, the function would only be
> called once.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
f4 to make constant xololady Microsoft Excel Misc 5 16th Jan 2009 08:58 PM
Is there a way to make a result from an IF or SUM a constant? wvilliers@hotmail.com Microsoft Excel Misc 1 8th Apr 2008 03:04 PM
When I do an @sum, is there anyway to make the sum a constant ? =?Utf-8?B?YnVmZmFsbzE=?= Microsoft Excel Worksheet Functions 5 14th Sep 2006 02:27 PM
Make one row a constant display? MRW Microsoft Excel Misc 3 22nd Nov 2005 10:01 PM
Can you make a static constant? Phill Microsoft C# .NET 2 16th Nov 2004 01:36 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:44 AM.