Reputation: 1
i am trying to access a class object in different form to call its method ..can u plz tell me how can i do it..? here is my code..
Dim a As customers
Private Sub Command1_Click()
Dim txt1 As String
Dim txt2 As String
Set a = New customers
txt1 = Text1.Text
txt2 = Text2.Text
a.userid = txt1
a.log_in txt1, txt2
End Sub
its a code i have written in form 1....for login.. made an object for customer n called loging procedure... in that if it sucesfully logs in i m opening a new form homw.show only.. and in home...... option is there view profile in which i am showing another form profile and in its load method want to call a's another method for displaying profile.. how it can know whose profile it should display....here i m getting cofused as m new to vb help me out...plz..
Upvotes: 0
Views: 1459
Reputation: 11991
Implement an init method on the second form and use it in Command1_Click like this
...
a.userid = txt1
a.log_in txt1, txt2
Dim oFrm As Form2
Set oFrm = New Form2
oFrm.Init a
End Sub
In Init
you can call Show
to display the instance of Form2
. You can also move everything you do in Form_Load
to this simple Init
method -- like filling comboboxes etc.
Upvotes: 1