Create Active-X control with methods that only run during run time Visual Basic 6

Posted on 2009-04-15
Last Modified: 2013-11-25
I am creating methods that read and write to a database. I don't want these methods to run during design time. I consider design time when the user embeds an active-x control in a container. I want these methods to run during run-time. What is happenning now is that when I embed the control into a container (excel vba editor), I get database connection errors because some database properties that I expect to be configured by the user aren't set. These methods are used to initialize the values on the control during run-time
Question by:adimit
    LVL 39

    Assisted Solution

    (I thought I remember that VB6 contained a single method for finding that you are in design time or not. According to this post I was wrong:, which shows a complex way of dealing with runtime/design time.)

    However, I think what you are after is the Ambient.UserMode property, which is True for runtime and False for design time. Not sure whether you are creating a UserControl, I think so, because you talk of a container. If so, you can access this property through UserControl.UserMode.

    -- Abel --

    Author Comment

    the above works fine if placed in ambientchanged event of the usercontrol. However when I press f5 to compile and run the .ocx, vb opens the .ocx in internet explorer. Internet explorer does not detect the ambient changed event. If I place the .ocx on a user form in excel then the ambientchanged event triggers.  It seems that this event only triggers on a user form, but I also need it to trigger ins omething like Internet Explorer as well. any thought?
    LVL 39

    Assisted Solution

    Apparently you need to update. See this KB article from Microsoft:

    Accepted Solution

    I place the following code in the ambient changed event.

    if usercontrol.ambient.usermode = true then 'enter code here
    LVL 39

    Expert Comment

    But that was what we used all the time, didn't we, that's what was in my first comment, at least, that's what it was supposed to be about. Sorry if I wasn't clear, but glad you have a solution now.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
    You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
    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…

    758 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

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now