Solved

How to get correct dialogresult from myform.showdialog

Posted on 2013-02-06
4
447 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 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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
Course of the Month11 days, 14 hours left to enroll

623 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