Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to pass Login info captured in the Login form to the mainform

Status
Not open for further replies.

santosh1

Programmer
Apr 26, 2002
201
0
0
US
How can I pass Login info (userID, password, server, database) from the Login form to the mainform before Load event is fired in the main form?
The reason being that I need to capture the Login info to build a connection string and only will be able populate the main form. I appreciate your help. S.

dim connectionString as string ="Provider=SQLOLEDB.1;Persist Security Info = False;" & _
"Initial Catalog = " & database & ";Data Source = " & Server & ";User ID =" & userName & ";Password =" & password & ";"
 

either you can create Public property in MainForm to hold Login information from Login form.

' Define a local variable to store the property value.
Private connStringVal As String
' Define the property.
Public Property connString() As String
Get
Return connStringVal
End Get
Set(ByVal Value As String)
connStringVal = Value
End Set
End Property

and then on click event of OK button on Login form

Dim frm As New yourMainForm()
frm.connString = "your Connection String"
frm.ShowDialog(me)

or you can add a module in your project and create your connection string in the module. This way you can use it anywhere in your project.

Module modUtilities
Public strConn As String = "Server=(local);Database=Library;Integrated Security=True;"
Sub Main()
Dim frm As New yourLoginForm()
frm.ShowDialog()
End Sub
End Module



 

either you can create Public property in MainForm to hold Login information from Login form.

' Define a local variable to store the property value.
Private connStringVal As String
' Define the property.
Public Property connString() As String
Get
Return connStringVal
End Get
Set(ByVal Value As String)
connStringVal = Value
End Set
End Property

and then on click event of OK button on Login form

Dim frm As New yourMainForm()
frm.connString = "your Connection String"
frm.ShowDialog(me)

or you can add a module in your project and create your connection string in the module. This way you can use it anywhere in your project.

Module modUtilities
Public strConn As String = "Server=(local);Database=Library;Integrated Security=True;"
Sub Main()
Dim frm As New yourLoginForm()
frm.ShowDialog()
End Sub
End Module


Email: pankajmsm@yahoo.com
 
Thanks pankajBanga,

I created the public property in the main form. The problem is while creating a new form
from the login form, the form load event fires in the main form where I have the populate form
routine, this doen't me chance to pass the connString value to this routine and it fails.
Is there a way to resolve this? S.
 

why don't you call your populate subroutine on Form Laod event of main form & pass the connection string there. Try this!!!

1. Create Public Property for Main form.

' Define a local variable to store the property value.
Private connStringVal As String
' Define the property.
Public Property connString() As String
Get
Return connStringVal
End Get
Set(ByVal Value As String)
connStringVal = Value
End Set
End Property

2. On click of OK button on Login form call the main form.

Private Sub onbtnOKClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click

Dim frm As New yourMainForm()
frm.connString = "your Connection String"
frm.ShowDialog(me)

End Sub

3. On form load event of main form call populate subroutine and pass the connection string

Private Sub onFormLoad(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load

'Call populate subroutine & pass connection string.
Populate(me.connString)

End Sub


Email: pankajmsm@yahoo.com
 
Thanks PankajBanga, it worked really well. S.

 
I got a bad error ' System.OutofMemoryException' while using connString before the mainform.show. Any workaround? Thanks. S.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top