PC Review


Reply
Thread Tools Rate Thread

Best way to transfer variables between functions

 
 
tobesurveyor via AccessMonster.com
Guest
Posts: n/a
 
      17th Apr 2006
Good Morning,
I am a novice when it comes to VBA. I have made a couple of applications
using the same methods of using VBA. I am now going back and trying to make
things quicker as well as trying to clean up my code.

Is there a way to pass variables between functions in code?
Right now I have an OnClick event to call Launch01 thru Launch14 based upon
the image they click on the form. When they click on of these, the area
clicked highlights. I want that highlight color to change based upon an
option in a table called tblChoiceMenuColor. Unfortunately I do not know how
to transfer the variable solved for in the Private Sub FindColor for the
variable ColorCode to each Me.bxLaunch##.BackColor in each OnClick event.
Please see below.

Private Sub FindColor()

ColorNameID = DLookup("[ChoiceMenuColorID]", "tblLocalSettings",
"[LocalSettingsID] = 1")
ColorImgName = DLookup("[FileName]", "tblChoiceMenuColor", "
[ChoiceMenuColorID] = " &
ColorNameID)
ColorCode = DLookup("[ColorCode]","tblChoiceMenuColor","
[ChoiceMenuColorID] = "& ColorNameID)
End Sub

Private Sub Launch01()
FindColor
Me.bxLaunch01.BackStyle = 1
Me.bxLaunch01.BackColor = 16250335 <<<<I want to pass the variable
ColorCode Here
End Sub

Private Sub Launch02()
FindColor
Me.bxLaunch02.BackStyle = 1
Me.bxLaunch01.BackColor = 10485760 <<<<I want to pass the variable
ColorCode Here
End Sub

Any help would be greatly appreciated.
Thanks,
CF

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...dules/200604/1
 
Reply With Quote
 
 
 
 
=?Utf-8?B?QkFD?=
Guest
Posts: n/a
 
      17th Apr 2006
Make FindColor a function rather than a sub:

Function FindColor()
>
> ColorNameID = DLookup("[ChoiceMenuColorID]", "tblLocalSettings",
> "[LocalSettingsID] = 1")
> ColorImgName = DLookup("[FileName]", "tblChoiceMenuColor", "
> [ChoiceMenuColorID] = " &
> ColorNameID)
> ColorCode = DLookup("[ColorCode]","tblChoiceMenuColor","
> [ChoiceMenuColorID] = "& ColorNameID)


FindColor = ColorCode 'Comment: Since it's this code you want to pass back
to sub
> End Function



Now in the Launch codes:

Private Sub Launch01()
> colorIwant = FindColor
> Me.bxLaunch01.BackStyle = 1
> Me.bxLaunch01.BackColor = ColorIWant
> End Sub


Since you've got multiple launch codes I would declare the Variable
ColorIWant as (at minimum) Public and would set the Function Findcolor
outside of the Form's code

BAC


"tobesurveyor via AccessMonster.com" wrote:

> Good Morning,
> I am a novice when it comes to VBA. I have made a couple of applications
> using the same methods of using VBA. I am now going back and trying to make
> things quicker as well as trying to clean up my code.
>
> Is there a way to pass variables between functions in code?
> Right now I have an OnClick event to call Launch01 thru Launch14 based upon
> the image they click on the form. When they click on of these, the area
> clicked highlights. I want that highlight color to change based upon an
> option in a table called tblChoiceMenuColor. Unfortunately I do not know how
> to transfer the variable solved for in the Private Sub FindColor for the
> variable ColorCode to each Me.bxLaunch##.BackColor in each OnClick event.
> Please see below.
>
> Private Sub FindColor()
>
> ColorNameID = DLookup("[ChoiceMenuColorID]", "tblLocalSettings",
> "[LocalSettingsID] = 1")
> ColorImgName = DLookup("[FileName]", "tblChoiceMenuColor", "
> [ChoiceMenuColorID] = " &
> ColorNameID)
> ColorCode = DLookup("[ColorCode]","tblChoiceMenuColor","
> [ChoiceMenuColorID] = "& ColorNameID)
> End Sub
>
> Private Sub Launch01()
> FindColor
> Me.bxLaunch01.BackStyle = 1
> Me.bxLaunch01.BackColor = 16250335 <<<<I want to pass the variable
> ColorCode Here
> End Sub
>
> Private Sub Launch02()
> FindColor
> Me.bxLaunch02.BackStyle = 1
> Me.bxLaunch01.BackColor = 10485760 <<<<I want to pass the variable
> ColorCode Here
> End Sub
>
> Any help would be greatly appreciated.
> Thanks,
> CF
>
> --
> Message posted via AccessMonster.com
> http://www.accessmonster.com/Uwe/For...dules/200604/1
>

 
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
Optional Variables in Functions (REPLACE and other 'Worksheet' functions) Evi Microsoft Access Queries 2 6th May 2008 09:59 PM
Using variables in functions Natan Microsoft Excel Worksheet Functions 1 27th Aug 2004 05:53 AM
Returning Variables from Sub Functions Dickie Microsoft Access Form Coding 0 4th Aug 2004 02:18 PM
Variables in Functions? Tony Microsoft Excel Worksheet Functions 2 13th Jul 2004 07:40 PM
Conditional Functions - logical functions based on volatile variables WorkerB5 Microsoft Excel Worksheet Functions 2 14th May 2004 11:20 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:01 AM.