Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 20th, 2007, 06:08 AM
Registered User
Join Date: Jul 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Option Group Variables (from Form to Module)

Hello all, I am a new user of VBA for both Excel and Access.

I have created for the Hedgefund in which I am working, the database to store all the useful information relative to the company business, and the reports which show test results and ratios.
THe database now works with the information of ONE Portfolio investment.
Now I need to shape the database in a way that it is possible to manage more than one "portfolios investment", storing all the data in the same database and leaving the user the opportunity to select at the begnning the Portfolio to be analysed.

The main idea to solve this problem was the creation of an extra coloumn in every Table in which are stored the Portfolio's data.
This coloumn will contain the "number of the portfolio" from which the data has been uploaded (eg. "1" = Portfolio #1 etc...)
Everytime the user chooses the portfolio to be analysed by clicking on the right "option group cell", a variable called "P" gets the value that will be compared with the one of the "Portfolio's number coloumn" during each test...and the database will keep calculating the tests for the particular portfolio until the user will change again the value "P" from the Option Group.

I positioned the option group on the FIRST Form of my database.
If a person does not touch the option group, The Portfolio #1 will be automatically selected, with the value of the variable P = "1".
The problem arises as I am not able to create "P" as a Global Variable.
If P is global: despite its value is saved in the VBA code of this FIRST FORM, it would be possible to read the P value also in all the other forms and Modules ( because in the modules I created the algorhitms to calculate the tests, and without the right value of P the database would show me the info about the wrong Portfolio).

Does someone knows how to declare P as Global Variable, or how to let the functions which run the test, take in input the P variable from the current value of the FRONT FORM?
Thankyou in advance!

Private Sub Frame19_AfterUpdate()
    P = Me.Frame19.Value
End Sub

Reply With Quote
  #2 (permalink)  
Old July 20th, 2007, 03:58 PM
Friend of Wrox
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts

If you put into any module (except a Class module)
Public P As Integer  ' (or whatever type fits your need)
then all code in your project (including objects) will have access to it to read it or change it.

You could add to your 1st form
Private Sub Form_Activate()
    P = Me.Frame19.Value
End Sub
This might go better in _Load(). The idea is that it will run one time to initialize your variable.
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Create Check Boxes/Option buttons/Option Group hewstone999 Access VBA 1 March 14th, 2008 07:25 AM
Array & Collections, Option Private Module ramk_1978 Beginning VB 6 1 January 19th, 2005 01:06 PM
Hide Subform Using Option Group martinaccess Access 1 October 3rd, 2004 10:48 AM
Option group vnadig Access 6 September 8th, 2004 02:53 PM
Option Group Procedures Mr.Crud Access VBA 7 February 12th, 2004 06:45 PM

All times are GMT -4. The time now is 03:57 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.