Solved

Simple Question about variables (Public)

Posted on 2003-11-07
6
184 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 51

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

685 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