Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to get correct dialogresult from myform.showdialog

Posted on 2013-02-06
4
Medium Priority
?
450 Views
Last Modified: 2013-02-06
I have a main form that I load, and the first thing it does is load another login form.  I need to get the result of the form, which I am able to do, but if they have the wrong password, I want to ask them to try again or cancel.  Its that dialogresult I don't seem to to catch.  Here is the load function of the main form.

 Private Sub frmMaintenance_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim myLogin As New frmSetupLogin
        If myLogin.ShowDialog = Windows.Forms.DialogResult.OK Then
            Dim mVersion As String = Application.ProductVersion.ToString
            Dim myUtil As New InspectionSetup
            mSetupMarkUp = myUtil.GetSetupMarkup
            Me.Text = Me.Text & Space(10) & "Version  " & mVersion
        Else
            Dim i As Integer
            i = MsgBox("Invalid password", MsgBoxStyle.RetryCancel)
            If i = vbCancel Then
                End
            Else
                myLogin.ShowDialog()
                ' myLogin.ShowDialog()
            End If
        End If
    End Sub

Here is the code in the login form click event

 Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
        If txtPassword.Text = "xxxxxx" Then
            Me.DialogResult = DialogResult.OK
        Else
            Me.DialogResult = Windows.Forms.DialogResult.No

        End If
    End Sub

thanks in advance.
0
Comment
Question by:mgmhicks
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 39

Expert Comment

by:appari
ID: 38862178
code looks fine to me, only modification i suggest is frmMaintenance_Load event.
change your existing frmMaintenance_Load event to
 Private Sub frmMaintenance_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim myLogin As New frmSetupLogin
        While True


            If myLogin.ShowDialog = Windows.Forms.DialogResult.OK Then
                Dim mVersion As String = Application.ProductVersion.ToString
                Me.Text = Me.Text & Space(10) & "Version  " & mVersion
                Exit While
            Else
                Dim i As Integer
                i = MsgBox("Invalid password", MsgBoxStyle.RetryCancel)
                If i = vbCancel Then
                    End
                Else
                    'myLogin.ShowDialog()
                    ' myLogin.ShowDialog()
                End If
            End If
        End While

    End Sub

Open in new window

0
 

Author Comment

by:mgmhicks
ID: 38862238
thanks appari, that is much better, but if I click nothing in password, it comes back and asks to retry, that's good.  But when I then enter the correct password, I have to click ok 2 times before it takes, then goes into the program.  This is what the code looks like now.

Dim myLogin As New frmSetupLogin

        While True
            If myLogin.ShowDialog = Windows.Forms.DialogResult.OK Then
                Dim mVersion As String = Application.ProductVersion.ToString
                Dim myUtil As New InspectionSetup
                mSetupMarkUp = myUtil.GetSetupMarkup
                Me.Text = Me.Text & Space(10) & "Version  " & mVersion
                Exit While
            Else
                Dim i As Integer
                i = MsgBox("Invalid password", MsgBoxStyle.RetryCancel)
                If i = vbCancel Then
                    End
                Else
                    myLogin.ShowDialog()
                    ' myLogin.ShowDialog()
                End If
            End If
        End While
0
 
LVL 39

Accepted Solution

by:
appari earned 2000 total points
ID: 38862276
remove the  
myLogin.ShowDialog()
in the else part
Dim myLogin As New frmSetupLogin

        While True
            If myLogin.ShowDialog = Windows.Forms.DialogResult.OK Then
                Dim mVersion As String = Application.ProductVersion.ToString
                Dim myUtil As New InspectionSetup
                mSetupMarkUp = myUtil.GetSetupMarkup
                Me.Text = Me.Text & Space(10) & "Version  " & mVersion
                Exit While
            Else
                Dim i As Integer
                i = MsgBox("Invalid password", MsgBoxStyle.RetryCancel)
                If i = vbCancel Then
                    End
                End If
            End If
        End While 

Open in new window

0
 

Author Closing Comment

by:mgmhicks
ID: 38862301
That did it.  Thanks a lot.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question