I ve got a propertyin my class that I have given the task of holding the username of the person that logged in and I would want to access that username in another form anoother time.How do I go about this? this is the code for my property:

Private _LogInUser As String = String.Empty
Public Property LogINUserName() As String
    Get
        Return _LogInUser
        'LogINUserName = _LogInUser
    End Get
    Set(ByVal value As String)
        _LogInUser = value
    End Set
End Property

this is how I am assigning my value to the property in my login form

 'Private comm1 As CommManager = New CommManager' the new instance of the class

Dim sql As String = "SELECT reference,UserName,UserPassword,UserCompany FROM Users WHERE UserCompany = '" & cmbCompany.Text & "' " 
Conn.Open() 
Dim dt As DataTable = New DataTable 
Dim dscmd As New OleDbDataAdapter(sql, Conn) 
dscmd.Fill(dt) Conn.Close() 
If dt.Rows(0)("UserName") = cmbUsername.Text Then 
If dt.Rows(0)("UserPassword") = txtPassword.Text Then 
comm1.LogINUserName = dt.Rows(0)("UserName").ToString 'Assign my value right here 
'MsgBox(comm1.LogINUserName) frmMenu.Show() 
Else MsgBox("Wrong Password and/or Username") '***In the case of wrong Password 
Exit Sub 
End If 
Else 
MsgBox("Wrong Password and/or Username") '***In the case of wrong UserName Exit Sub End If

how I expect to get my value

   Label11.Text = comm1.LogINUserName

I guess u want to display the username from the login form to main form after successful login, am i RIGHT??

if txtUsername has the text for username then while calling the second form u can write as below

'this code is to be written in in form1 before calling form2

Form2.Textbox1.Text = txtUsername.Text
Form2.show()

Guess this is what u want....

You have a couple of options for keeping records of who is logging in.
1)Database*
2)Program's Settings (XML)
3)Text FIle
4)CSV File

*The most reliable.

Keep a track of the user logged in the application and save the value in database and then u can call the value to ur next form with the help of select query

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.