Pass values back from a modal window

  • Thread starter Thread starter Roger Twomey
  • Start date Start date
R

Roger Twomey

I am a newbie to windows programming (I have been doing web and SQL for some time). So I have what is probably a very simple question, but of course I don't know the answer.

I have a form, the use clicks a login button, a modal window pops open:
Dim objLoginForm As New frmLogin

objLoginForm.ShowDialog()

They enter a username and password, if it passes validation I want to pass the user ID back to the parent form and close the modal window. I can close the modal window, I just can't figure out how to pass back the UserID.

How would I do that??
 
Add a public field for user ID to the main form class.

Public UserId As String ' Or integer or whatever you want

And add a public field to the objLoginForm for link to Main Form.

Public ParentForm As MyManForm

Open login form like this:
Dim objLoginForm As New frmLogin
objLoginForm.ParentForm = Me
objLoginForm.ShowDialog()

On closing login form set the value of user id. In the login form:
Me.ParentForm.UserId = some_user_id
Me.Close()
Best regards,
Gaidar



I am a newbie to windows programming (I have been doing web and SQL for some
time). So I have what is probably a very simple question, but of course I
don't know the answer.

I have a form, the use clicks a login button, a modal window pops open:
Dim objLoginForm As New frmLogin
objLoginForm.ShowDialog()
They enter a username and password, if it passes validation I want to pass
the user ID back to the parent form and close the modal window. I can close
the modal window, I just can't figure out how to pass back the UserID.
How would I do that??
 
This looks like what I want to do, however, I get this error:
Property 'ParentForm' is 'ReadOnly'.

when I try to set the parent form to 'Me'.

Do I need to create an MDI window and make it the parent of both??
 
Back
Top