Solved

Simple Question about variables (Public)

Posted on 2003-11-07
6
185 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 76

Expert Comment

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

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

Independent Software Vendors: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
vb6 connector to mongodb 2 160
vbModal 12 73
Dinamic report to Crosstab query 9 59
Remove Exif Orientation before adding image to db 9 61
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.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

737 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