Solved

How to get correct dialogresult from myform.showdialog

Posted on 2013-02-06
4
406 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
  • 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 500 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now