SHBrowseForFolder or what?

Create a simple standard exe and add 2 forms. On each form add 1 command button

On form1

Option Explicit

Private Sub Command1_Click()

Form2.Show vbModal
End Sub

On form2

Option Explicit
' private variables declaration
    HwndOwner As Long
    PidlRoot As Long
    PszDisplayName As String
    LpszTitle As String
    UlFlags As Long
    Lpfn             As Long
    lParam           As Long
    IImage           As Long
End Type
Private Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long

Private Sub Command1_Click()
    On Error Resume Next
    Info.PidlRoot = &H12
    Info.LpszTitle = "Select Computer Name:"
    Info.UlFlags = &H1000
    Info.PszDisplayName = Space$(256)
    SHBrowseForFolder Info
    If (Asc(Mid$(Info.PszDisplayName, 1, 1)) <> 32) Then
        Debug.Print Left(Info.PszDisplayName, InStr(Info.PszDisplayName, Chr$(0)) - 1)
        Exit Sub
    End If
End Sub

When I click on form2 button, SHBrowseForFolder starts up and wait for user input.

However, I still can click on form2 and even exit the form1 and let the program hanging there if I don't touch the SHBrowseForFolder. How do I prevent this. I would like the user cannot exit the form1 or form2 without selecting the path
LVL 26
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Richie_SimonettiIT OperationsCommented:
HwndOwner member is setted to form2.hwnd?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Richie_SimonettiIT OperationsCommented:
Also, there is another parameter when you use vbmodal, i can't remember and  i haven't vb installed to check...
Richie_SimonettiIT OperationsCommented:
it should be

Form2.Show vbModal, me
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

EDDYKTAuthor Commented:
Sometime long hour work will drive you crazy and cannot think

>>Form2.Show vbModal, me

doesn't work


HwndOwner member is setted to form2.hwnd?




Richie_SimonettiIT OperationsCommented:
I know the feeling. Thanks for "A" grade.
EDDYKTAuthor Commented:
You're welcome

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.