Solved

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

Posted on 2011-09-19
5
211 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
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…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

732 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