Solved

How to end from ActiveX DLL?

Posted on 1999-01-20
8
167 Views
Last Modified: 2010-05-03
hi,
I have a VB .exe which calls a function A from VB ActiveX DLL.
in function A, I have a message box. If the user selects  Yes, action will be done, else nothing is performed.
When I chose No, the form still appears. I tried to use the End keyword but it seems that this keyword can't be used in DLL.

Please advise how can i answer No and make the form disappears.

thanks,
andrea
0
Comment
Question by:andreat
8 Comments
 
LVL 4

Expert Comment

by:gencross
ID: 1469753
Use unload formname and in the unload event say...Set objectDllName = Nothing

This should get rid of the reference to the Dll and close the form.


0
 

Author Comment

by:andreat
ID: 1469754
hi gencross,
just to further elaborate my qn,
actually, the message box is on a dummy form with no controls.
the codes are :
calling function
----------------
Private WithEvents mform As fdialog
with mform
   .show vbmodal
end with

fdialog
-------
Private Sub Form_Load()
Dim msg, style, title, Help, Ctxt, response, MyString
msg = "Do you really want to stop all operations?"
style = vbYesNo + vbQuestion + vbDefaultButton2
title = "Stop Operation"
response = MsgBox(msg, style, title)
If response = vbYes Then
    'perform some actions
End If
End Sub

so in this case, I can't use unload in the form_load right?
Please advise.
thanks
andrea
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1469755
1) You can't unload in form_load that does not work. You can unload in form_activate or form_show. Just put a variable to true and test for this variable in form_show for example.

2) End in a dll does not work. The dll function should return a value or something on which the client should test. The client can now unload in this case.

Please reject the answer of gencross if it is not sufficient.
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 10

Expert Comment

by:caraf_g
ID: 1469756
You can do something about your Show problem.

Create a new Sub in your form as follows:

Public Sub ExternalShow(objOwnerForm As Form, intMode As Integer)

Within this sub you can execute all the code that you have put into the Form_Load procedure

Dim msg, style, title, Help, Ctxt, response, MyString
msg = "Do you really want to stop all operations?"
style = vbYesNo + vbQuestion + vbDefaultButton2
title = "Stop Operation"
response = MsgBox(msg, style, title)
If response = vbYes Then
    'perform some actions
    Me.Show intMode, objOwnerForm
End If

And to call the form:
Private WithEvents mform As fdialog
with mform
   .ExternalShow vbmodal, Me
end with

(You can adapt the sub to
- not have an objOwnerForm parameter if you don't need it
- not have an intMode parameter if you're always going to show the form either modeless or modal.)
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 1469757
You are free to unload the form within this sub
Unload Me

or from outside; it's up to you.
0
 

Author Comment

by:andreat
ID: 1469758
the answer is insufficient.

Mirkwood & caraf_g, I will try out your suggestions and then
revert to you for answering.

thanks,
Andrea
0
 

Author Comment

by:andreat
ID: 1469759
caraf_g : I've tried your suggestion but I get error 13 on
ExternalShow Me


Mirkwood : for my problem above, i can't return a value from form_load right? does it mean that I have to create another function X in fdialog and return a value from X? if that's the case, how do i call the function X from the calling project?

thanks,
andrea
0
 
LVL 10

Accepted Solution

by:
caraf_g earned 20 total points
ID: 1469760
You could "Translate" the intMode parameter, let's say you decide that 1 = modeless, and 2 = modal.

You can then change the code as follows

If response = vbYes Then
    'perform some actions
    If intMode = 1 then
        Me.Show vbModeless, objOwnerForm
    Else
        Me.Show vbModal, objOwnerForm
    End If
End If

Please note that you must call the procedure with 2 parameters, for example

   .ExternalShow 1, Me
or
   .ExternalShow 2, Me

Good luck
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Sending a email via excel using vba 6 100
Adding to a VBA? 6 78
Search combo error "Data Type Mismatch in Criteria Expression" 2 71
How to read File Date Created using VB6 8 52
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

821 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