Solved

Simple Question about variables (Public)

Posted on 2003-11-07
6
181 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
Comment Utility
Put the Public declarations in the Declarations section of the form.
0
 
LVL 49

Expert Comment

by:Ryan Chong
Comment Utility
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
Comment Utility

Dim, Public and Const are not executable, so there is no point in putting them in conditional parts of the procedure.
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 1

Accepted Solution

by:
Crazy_king_in earned 50 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Hi WrinMokka
Thanx for that points.. All the best...
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…

763 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

10 Experts available now in Live!

Get 1:1 Help Now