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

Posted on 2011-09-19
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.


Question by:Bruj
  • 3
  • 2
LVL 24

Expert Comment

ID: 36565291

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.



Author Comment

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....

LVL 24

Accepted Solution

Bitsqueezer earned 500 total points
ID: 36568817

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.



Author Closing Comment

ID: 36718841
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!
LVL 24

Expert Comment

ID: 36719747

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.



Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How can you open the FORM2 2 31
Delete QueryDef IF it Exists: Access VBA 5 34
IIF help, YN field 7 22
Microsoft Access Reports & Sub Reports 3 13
Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
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…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

770 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