+ Reply to Thread
Results 1 to 5 of 5

Public Variable

  1. #1
    Registered User
    Join Date
    03-28-2007
    Posts
    27

    Public Variable

    Hello,

    I have a problem with using one variable (username) in several UserForm captions. My code is:

    UserForm - frmLogin
    PHP Code: 
    Option Explicit
    Public user As String

    If "secret" Then MsgBox ("Successful 1 - John!")
           
    Unload Me
    user 
    "John"
           
    UserForm2.Caption "Admin - " user
           UserForm2
    .Show 
    UserForm2.Caption is correct but then:

    UserForm1 code:
    PHP Code: 
    Public user As String
    Private Sub CommandButton5_Click()
        
    Unload Me
        UserForm1
    .Caption "Form 1 - " user
        UserForm1
    .Show
    End Sub 
    On UserForm1 the Caption is not showing
    Last edited by VBA Noob; 04-09-2007 at 10:25 AM.

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    Its not the public deleration of user as the problem. When you Unload the userform, it looses all the data. including the value of user. I'd recommend that you hide, rather than unload the form.

    Please Login or Register  to view this content.
    or use Repaint
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    03-28-2007
    Posts
    27
    When I put Hide Me - it returns Compile Error: Wrong number of arguments or invalid prperty assignment

    When I use withour Hide Me:
    PHP Code: 
    Public user As String 
    Private Sub CommandButton5_Click() 
        
    UserForm1.Caption "Form 1 - " user 
        UserForm1
    .Show 
    End Sub 
    UserForm1 loads but user is not showing.

    When I use:
    PHP Code: 
    Public user As String 
    Private Sub CommandButton5_Click() 
        
    UserForm1.Caption "Form 1 - " user 
        UserForm1
    .Repaint
    End Sub 
    and click the button nothing happens.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello Digitborn.com,

    Move your statement Public user As String to the Delcarations sections of a Standard VBA Module. All your Forms as well as anyother code will have access to this Public Variable.

    Sincerely,
    Leith Ross

  5. #5
    Registered User
    Join Date
    03-28-2007
    Posts
    27
    That's it! This time it works. I didn't recognize that before you tell me, thanks!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1