Solved

Simple Question about variables (Public)

Posted on 2003-11-07
6
182 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 49

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now