[RESOLVED] My Form is on top of my Word document that I have just opened
I am quite a rookie on VB.net, but have been programming one way or another for over 40 years, I still have trouble getting my head around things, hence my probably very simple question ...
I have the following code that works, but my Form is reappearing on top of the just opened Word document. How can I make the Word document appear on top ?
I am still in Debug mode, but presume that makes no difference ...
Thanks in advance ...
Code:
Imports Microsoft.Office.Interop.Word
Imports Microsoft.Office.Interop
Public Class Form2
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If TextBox1.Text = "" Then
Form3.TextBox1.Text = "Error, you have not entered a name for this Artist or Band ..."
Form3.TextBox2.Visible = False
Form3.Button2.Visible = True
Form3.AcceptButton = Button2
Form3.Show()
Exit Sub
End If
MusicFile = TextBox1.Text & ".docx"
If System.IO.File.Exists(MusicFolder & MusicFile) Then
Form3.TextBox1.Text = "Error, you already have an existing file for this Artist or Band ..."
Form3.TextBox2.Text = "Do you want to open that file or go back to the previous screen ?"
Form3.Button1.Visible = True
Form3.Button3.Visible = True
Form3.AcceptButton = Button1
Form3.Show()
Else
If SheetOrientation = "Portrait" Then
System.IO.File.Copy(MusicFolder & "Portrait.docx", MusicFolder & MusicFile)
End If
If SheetOrientation = "Landscape" Then
System.IO.File.Copy(MusicFolder & "Landscape.docx", MusicFolder & MusicFile)
End If
System.IO.File.SetAttributes(MusicFolder & MusicFile, fileAttributes:=vbNormal)
WordApp = CreateObject("Word.Application")
WordApp.Visible = True
WordDoc = WordApp.Documents.Add(MusicFolder & MusicFile)
Me.Close()
End If
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Me.Close()
End Sub
End Class
Re: My Form is on top of my Word document that I have just opened
Originally Posted by boops boops
I'm a bit uncertain what you mean by "my form": your image shows Form1 in the title, and your code refers only to Form2 and Form3. Anyway, something you can easily try is to provide the "owner" argument in the Form.Show statement. For example:
Code:
Form2.Show(Me)
Assuming "Me" refers to Form1, that statement will ensure that Form1 is the Owner of Form2, with the result that Form2 will always appear in front of Form1.
EDIT: I guess you can't change how the Word document is shown. Perhaps it will help to make Forms 2 and 3 owned by Form1, and Hide Form1 as soon as you want all 3 forms to get out of the way.
BB
boops boops, Form1 has 3 options for the user, Open an existing file, Create a new Portrait File, Create a new Landscape File & Form2 then opens if option 2 or 3 is chosen. Form2 just contains a TextBox for the user to enter the name of his Artist or Band and this is the Code that sits behind Form2. Form3 is an Error box, otherwise I create a new Word document in the Orientation he has requested and open it for him to enter data ... this all worked fine when I was opening an Excel file, I have just realised, but now I have switched it to a Word file, Form1 pops up in front of it and that is all I want to prevent.
This is just a small program for an old man who has brain damage I am trying to make it easy for him to do what he wants to do, it's so frustratingly annoying to run into such a stupid problem when it's basically finished !!!