Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I haven't had any luck finding a solution to this problem:

 

Given an MDI app, the user opens a new document window. In the ID text field, they type an ID (say "123"). They open another child document and type the ID "123" again. What I need to do is close the most recent child document and give focus back to the document that already had "123" as the ID.

 

The code I am trying to use:

 

   Private Sub txtFolioNumber_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtFolioNumber.LostFocus
       Dim frm As frmDocument

       For Each frm In Me.MdiParent.MdiChildren
           'no need to check myself (the current form)
           If (Me.Handle.ToInt32 <> frm.Handle.ToInt32) Then
               'if the number just entered is already used on another form, switch to that form
               If (frm.txtFolioNumber.Text = txtFolioNumber.Text) Then
                   frm.TopMost() = True
                   Me.Close()
               End If
           End If
       Next frm

   End Sub

 

I also posted this problem at VisualBasicForum.com (in the .Net section) but haven't found a solution yet.

 

http://www.visualbasicforum.com/showthread.php?t=232374

 

tia,

flynn

Posted

I would suggest a different approach. Instead of just closing the form without warning, which will probably confuse the user, do something like:

 

Private Sub txtFolioNumber_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtFolioNumber.LostFocus
       Dim frm As frmDocument

       For Each frm In Me.MdiParent.MdiChildren
           'no need to check myself (the current form)
           If (Me.Handle.ToInt32 <> frm.Handle.ToInt32) Then
               'if the number just entered is already used on another form, switch to that form
               If (frm.txtFolioNumber.Text = txtFolioNumber.Text) Then
                   MessageBox.Show("This number already exists. Please enter a different number."
                   Exit For
               End If
           End If
       Next frm

   End Sub

 

Another approach would be to use just one form for entering the data and prompting the user if they enter a number that already exists:

 

If MessageBox.Show("Record already exists. Would you like to go to that record?", "Duplicate Record", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1))

 

Using one form is likely to be less confusing in the long run.

Here's what I'm up to.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...