Reputation: 1
I am having multiple forms with Find button provided. The forms i am having are Contacts.vb and Users.vb, i want to use single Find.vb form for both of these forms. I mean whether a user presses Find button from Contacts.vb or Users.vb the same form should be opened with corresponding data that is fetched from database.
I tried using Find.Owner = Me
from Users.vb but i don't know how can i determine from Find.vb that who is the owner.
I tried to use that if owner of find form is Users.vb then fetch data from users table and if owner is Contacts.vb then fetch data from Contacts table. Unfortunately i am not able to perform this task.
Please provide any proper solution or any other suggestion to perform this. Thanks in Advance
Upvotes: 0
Views: 11186
Reputation: 111
Call your children form using:
frmChildren.ShowDialog(Me)
Now, how to know which form called to the parent form? Using:
Me.Owner.Name
for example...
if Me.Owner.Name = "frmMain" then
MessageBox.Show("YES! Its called from frmMain")
else
MessageBox.Show("Its called from " & Me.Owner.Name)
End If
Maybe you need exactly this:
'To call your form Find.vb from a command button. (for example)
Find.ShowDialog(Me)
'How to know which form call to Find.vb ?
If Me.Owner.Name = "Contacts" then
'Actions for Contacts
ElseIf Me.Owner.Name = "Users" then
'Actions for Users
else
'Actions for NOT"Contacts" and NOT"Users"
end if
Upvotes: 9
Reputation: 5478
You should add a property to Find form as follows:
Private findTypeValue As FindType
Public Property FindType As FindType
Get
Return findTypeValue
End Get
Set (value as FindType)
findTypeValue = value
End Set
And create Enum for the property:
Public Enum FindType As Integer
Contacts = 0
Users= 1
End Enum
Then in Find form check the type:
If FindType = FindType.Contacts Then
...
Else
End If
Upvotes: 2
Reputation: 24988
Add a property (e.g. "PersonType") to the child form - set this from the parent just before showing the form - and then use the value of this property in the child to perform the correct search type.
Upvotes: 1