Search code examples
vb6

Using databse in VB6 how can I display data given in a form to another form?


In my VB6 project i have created company registeration form, login form and the main form(which deals with other activites for the project). Now registeration form and login form are working well and good but i am not able to display the company name in the main form which the user had enterd while registeration.

Tries:

  1. i have linked the label(where i am supposed to display company name in the main form) with the database which is used to record registeration details using properties of the label.

Basically what i want is whenever i login to the account using the login details i want to display my company's name in the main form (label1.caption) which i had enterd while registering.


Solution

  • You could simply refer to your login form in you main form's code. If your login form is called frmLogin for example and has a lblCompany label, you can access the label from the main form using:

    frmLogin.lblCompany.Caption
    

    There are better ways to do this though:

    1. You can create a property on your login form and read it after you've displayed the form.

    in frmLogin:

    Public Property Get Company() As String
        Company = lblCompany.Caption
    End Property
    

    in frmMain:

    Public Sub DisplayLogin()
    
        Dim frm As New frmLogin
        
        frm.Show vbModal
        
        MsgBox frm.Company
    
    End Sub
    
    1. Pass an object created in the main form to the login form that it updates during the login process.