Solved

How can I use a class module item on a FORM?

Posted on 2011-09-19
5
204 Views
Last Modified: 2012-05-12
I have a class that is an internet explorer. I like using this class as it makes my life SO Much easier (and I have almost finished my project using it...)
I would like to have 7 of these on a form that I can zoom in and out of.
I have the code that will allow me to adjust a "web browser control" that I put on the form, and I have modified the zoom function so that it works in my class.
Now what I am looking to do is to have all this working together.


I am looking for any suggestions,
Attached is a access database that has the userform I am testing, and also the class I have been using and want to use on the form instead of the "web control" Or can we modify the class so that it can be used for the control of the web controls? I need the multi instance capability and control that the class offers.

Thanks!!!!!



IEControlPanel-Test.accdb
0
Comment
Question by:Bruj
  • 3
  • 2
5 Comments
 
LVL 24

Expert Comment

by:Bitsqueezer
ID: 36565291
Hi,

you do not really have a class which IS a webbrowser - you only have a class which wraps a web browser class. A class in Access has no visual element and so it can only be used to manage non-visual things or manage visual things of a visual control (like a textbox).
The webbrowser ActiveX control is the visual element, also the form. But a form is also a class module which makes the complete form instantiable. So the simplest thing is: Create a blank form, insert a webbrowser ActiveX element, adjust it like you need and then add a class module global variable as "clsBrowser" and initialize it in FormLoad or FormOpen. If you add a public property which accesses this object variable then you can use all the functions of the class outside of the form.
The form then needs to be opened as object, not with DoCmd.OpenForm. Simply create a class variable like "Dim frmWeb As MyFormName" and then intantiate it with "Set frmWeb = New MyFormName". You can open the form with "frmWeb.Visible = True". The best thing is, because it is now used as a normal class but is not visible until you make it visible you can access all public properties - your own and the standard ones of the form, and therefore also the WebBrowser control. You could for example load the page invisible and show it when it's ready.
Of course you must adjust your "clsBrowser" a little bit to work with the ActiveX control. For example, in Access 2007 it is an external ActiveX control which is wrapped by Access, in Access 2010 it is now a real Access 2010 control which is a little bit different - but in all cases I saw the most functions worked in all versions, only the path to the right function is sometimes a little bit different.
In your example there is a reference to an OCX file which I do not have here on my current computer which only have A2007 so I cannot tell you more about this, but it looks very similar to the normal ActiveX webbrowser control.
With the form used as class you can open as many forms of the same type as you want so I guess that's what you need.

Cheers,

Christian
0
 

Author Comment

by:Bruj
ID: 36567346
Hey thanks!
I am not quite sure I understand though...
As for:In your example there is a reference to an OCX
It is not needed, I probably added it to the references trying to get things to work.

I currently have my browsers  named aBTSBrowser(1) through aBTSBrowser(6)
I take it I would then need to change it to  myformname.aBTSBrowser(1) etc....

Thanks!
Bruce
0
 
LVL 24

Accepted Solution

by:
Bitsqueezer earned 500 total points
ID: 36568817
Hi,

ah, OK, I didn't test it because it was called webbrowser so I thought this reference was needed by your class.

If your class does work with the normal ActiveX Webbrowser control then you could do it for example like this in a form:

Private objBrowser As clsBrowser

Public Property Get Browser() As clsBrowser
   If objBrowser Is Nothing Then Set objBrowser = New clsBrowser
   Set Browser = objBrowser
End Property

Open in new window


So now you could access your class with "frmBrowser.Browser.WhateverFunction...".
Another possibility which would make it easier is to simply insert everything you have in your class module into the form. You would then have a visual class module and if the functions are public you could access them in the same way as with your clsBrowser - with the difference that you could not only instantiate the form class (like described in my last posting) but also make it visible and add further visual elements if you need. Another advantage is that you are not forced to make it visible, you can instantiate the new form class like any other class module and simply don't make it visible - so both is possible.
The disadvantage is that a form class module can only be used in Access, for example in Excel there are user forms instead of forms. A non-visual class module can simply be exported to other VBA dialects and you can import it there (in Excel for example into a user form in a similar way like with the property method above) and go on using in the same way. If you only want to use it in Access I would say the form class module is the easier method.

Cheers,

Christian
0
 

Author Closing Comment

by:Bruj
ID: 36718841
Bitsqueezer
Thanks got it working,
On local system worked fine, but when I put it on a virtual system, it ran SO SO SLOW....
I have gone back to my origianl approach of just having the webpage as stand alone IE objects

Thank though very much!
0
 
LVL 24

Expert Comment

by:Bitsqueezer
ID: 36719747
Hi,

you're welcome.
But I see no reason why it should have a different performance on a virtual system if you do not try to run your virtual on a C64...;-)

Good that you got it to work.

Cheers,

Christian
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

757 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

20 Experts available now in Live!

Get 1:1 Help Now