Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

OL 2003 VB Macro- How to close an open dialog box?

Posted on 2006-04-13
16
Medium Priority
?
238 Views
Last Modified: 2010-04-08
I have a macro that opens a dialog box with command buttons in it.  Each button opens a child dialog box with txt boxes and when Go is clicked a new OLmessage window is suppose to open and be prefilled with the txt box info and HTML content from the code in the macro.

I say "suppose to" becuase it stops here with an error that basically says the initial dialog box called FrmChoose is still open.

How do I close this dialog after clicking one of the command buttons?

I tried several things, I thought me.hide would do it but it does not help.  I don't understand modal and modeless, could it be the culprit?


Here is the code for FrmChoose

Private Sub CommandButton1_Click()
'Opens a new NFS form
Dim a As New NFS
a.Show
Me.hide
'unload me
'a.hide
End Sub

Private Sub CommandButton2_Click()
'opens a new ACAT form
Dim b As New ACAT
b.Show
Me.hide
'Unload Me
'b.hide
End Sub

Private Sub CommandButton3_Click()
'Opens a new IRA form
Dim c As New ira
c.Show
Me.hide
'Unload Me
'c.hide
End Sub

Thanks,
...Jeff

0
Comment
Question by:jsheffer
  • 8
  • 7
16 Comments
 
LVL 18

Expert Comment

by:meintsi
ID: 16449690
Try ....

frm A.Show
Unload frmChoose
End Sub
0
 
LVL 1

Author Comment

by:jsheffer
ID: 16449855
I'm pretty sure I tried that, but I'll try again.  Look for another post.
0
 
LVL 1

Author Comment

by:jsheffer
ID: 16449868
Same outcome.  Thanks for playing though : )
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
LVL 76

Accepted Solution

by:
David Lee earned 2000 total points
ID: 16450778
Hi jsheffer,

I don't believe you're going to be able to unload or close FrmChoose with this code.  The problem is that FrmChoose is calling the other form, transfering program control to it.  I'm pretty sure the second form has to be able to return to the calling form (FrmChoose).  The way around this is to change the approach.  You need a main routine that loads and displays FrmChoose.  When the user clicks one of the buttons FrmChoose returns a value indicating which button was clicked.  The code then checks that value and loads/displays the second form.  Something like this.

Public intChoice As Integer

Sub Main()
    Dim x As New FrmChoose, _
        y As Object
    FrmChoose.Show
    Select Case intChoice
        Case 1
            Set y = New NFS
        Case 2
            Set y = New ACAT
        Case 3
            Set y = New IRA
    End Select
    Y.Show
    Set x = Nothing
    Set y = Nothing
End Sub

The code in FrmChoose would be something like this.

Sub CommandButton1_Click()
    intChoice = 1
    Unload Me
End Sub

Sub CommandButton2_Click()
    intChoice = 1
    Unload Me
End Sub

Sub CommandButton3_Click()
    intChoice = 1
    Unload Me
End Sub



Cheers!
0
 
LVL 1

Author Comment

by:jsheffer
ID: 16452420
BlueDevilFan, Thanks for the info.  I think I put it all in the right place.  Unfortunately when I step through the code, it does not work.

I've notice that stepping through, when it gets to the Case Select statements, it never hits the "set y=nfs" lines.  So I think that none of the cases are true.  It steps down to y.show and then I get a "Object Variable or With Block not set" error.

Here is the code which is cut and paste from your post.  Please let me know if I've put it in the wrong place.

"ThisOutlookSession"
Sub MAIN()
    Dim x As New FrmChoose, _
        y As Object
    FrmChoose.Show
    Select Case intChoice
        Case 1
            Set y = New NFS
        Case 2
            Set y = New ACAT
        Case 3
            Set y = New ira
    End Select
    y.Show
    Set x = Nothing
    Set y = Nothing
End Sub

"FrmChoose"
Sub MAIN()
    Dim x As New FrmChoose, _
        y As Object
    FrmChoose.Show
    Select Case intChoice
        Case 1
            Set y = New NFS
        Case 2
            Set y = New ACAT
        Case 3
            Set y = New ira
    End Select
    y.Show
    Set x = Nothing
    Set y = Nothing
End Sub
0
 
LVL 76

Expert Comment

by:David Lee
ID: 16452474
Are you sure that's the code you're using?  It looks to me like the code for both the form and for the main sub are identical.  I also don't see any sign of the public variable to hold a the result of the button click.
0
 
LVL 1

Author Comment

by:jsheffer
ID: 16452661
Sorry about that.  I was a bit hasty.

Here is the code for FrmChoose

Sub CommandButton1_Click()
    intChoice = 1
    Unload Me
End Sub

Sub CommandButton2_Click()
    intChoice = 1
    Unload Me
End Sub

Sub CommandButton3_Click()
    intChoice = 1
    Unload Me
End Sub

Can you eloaborate on the Public Variable comment.  I think I understand it in principle, but I don't know what to remedy it.

Thanks Again.  I've got to step out for a couple hours.  I'll be back on it as soon as I return.
..Jeff
0
 
LVL 76

Expert Comment

by:David Lee
ID: 16452678
The public variable I mentioned is a variable declared as being Public (i.e visible to all procedures) outside of any module.  That's required in this case because any variable declared within FrmChoose is going to be destroyed when FrmChose unloads, leaving nothing to tell us what selection the user chose.  Make sense?

No problem on being away.  I have to step away shortly too and am not sure when I'll be back.
0
 
LVL 1

Author Comment

by:jsheffer
ID: 16453799
Okay, so the statement "Public intChoice As Integer" which I placed in "thisOutlooksession" (also accidently omitted from my first code post) is in the wrong place????  Would you agree?

Public intChoice As Integer
Sub MAIN()
    Dim x As New FrmChoose, _
        y As Object
    FrmChoose.Show
    Select Case intChoice
        Case 1
            Set y = New NFS
        Case 2
            Set y = New ACAT
        Case 3
            Set y = New ira
    End Select
    y.Show
    Set x = Nothing
    Set y = Nothing
End Sub
0
 
LVL 76

Expert Comment

by:David Lee
ID: 16453989
No, it's in the right place.
0
 
LVL 1

Author Comment

by:jsheffer
ID: 16454088
Well I commented it out of "thisOutlookSession" and added it to module1 and it seems to work great.  Put it back in "thisoutlooksession" and still doesn't work.  Am I okay to leave it in module1?
0
 
LVL 76

Expert Comment

by:David Lee
ID: 16454103
Yes, it's okay to leave it in Module1.
0
 
LVL 1

Author Comment

by:jsheffer
ID: 16454169
Thanks, you're awesome.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 16454178
Thanks.  No problem.
0
 
LVL 1

Author Comment

by:jsheffer
ID: 16454215
I've got one more hurdle to overcome.  I'm posting a new 500 pt. question.  Has to do with saving a copy of this message in a public folder after sending.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 16454451
Ok.  I'll watch for it.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

With so many activities to perform, Exchange administrators are always busy in organizations. If everything, including Exchange Servers, Outlook clients, and Office 365 accounts work without any issues, they can sit and relax. But unfortunately, it…
There can be many situations demanding the conversion of Outlook OST files to PST format and as such, there is no shortage of automated tools to perform this conversion. However, what makes Stellar OST to PST converter stand above the rest? Let us e…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…
Suggested Courses

810 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