Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


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

Posted on 2011-09-19
Medium Priority
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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
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.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

578 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