Solved

Simple Question about variables (Public)

Posted on 2003-11-07
6
183 Views
Last Modified: 2010-05-01
I am trying to allow my two forms to read from each toerh and in future from other forms,
Everyone says to place
    Public UName As String
But this doesnt allow my other form to read the variable value
There may be something wrong within the rest of my code so I will place it here,
This is the sign up form which will eventually send the information to my database when I have enough knowledge to do that (not a request for help)

Private Sub cmdSubmitDetails_Click()
    Dim msgbox_1Submit                       'This is the button they click on after they have inputed their details
    msgbox_1Submit = MsgBox("Is this information correct?", 4, "Validation")
    Select Case msgbox_1Submit
    Case 7
    MsgBox "Please make the changes and then Select 'Submit'."
    Case 6
    Public UName As String                    'These are in the
    Public UAge As Integer                     'General declerations
    Public UCountry As String                 'Like i was told to do
    UName = txtEnterName.Text
    UAge = txtEnterAge.Text
    UCountry = txtEnterCountry.Text
    MsgBox "Successfully Submitted"
    MsgBox "Welcome " & UName & " who is " & UAge & " and lives in " & UCountry
    frmMain.Visible = True                     'Loads next form
    frmSubmitNew.Visible = False           'Gets rid of old form
    End Select
End Sub

The next form only has the one line for the moment.

Private Sub Form_Load()
    lblWelcome.Caption = "Hello " & UName & "."
End Sub

Help would be very much appreciated,
Thank you
Adam ;)
0
Comment
Question by:WrinMokka
6 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 9700088
Put the Public declarations in the Declarations section of the form.
0
 
LVL 50

Expert Comment

by:Ryan Chong
ID: 9700089
It's to be a good habit to define your public variable in module:

In a module:

    Public UName As String                    'These are in the
    Public UAge As Integer                     'General declerations
    Public UCountry As String                

cheers
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 9700115

Dim, Public and Const are not executable, so there is no point in putting them in conditional parts of the procedure.
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 1

Accepted Solution

by:
Crazy_king_in earned 50 total points
ID: 9700157
Hi,
As ryancys its a good practice to have the public variables in the module, If u dont want to add a module then declare the public variables in the general section.
When u go to the second form access the variable as FormName.VariableName, though it is not compulsory to do so, it is always a best practice to do this way.

Good Luck !!!
0
 

Author Comment

by:WrinMokka
ID: 9700220
Thanks for all your help, though you all helped a lot I gotta give Crazy_king_in the points because he solved me error
>When u go to the second form access the variable as FormName.VariableName, though it is >not compulsory to do so, it is always a best practice to do this way.
Id give you all points if I could but I cant, Thanks all the same
0
 
LVL 1

Expert Comment

by:Crazy_king_in
ID: 9700446
Hi WrinMokka
Thanx for that points.. All the best...
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question