[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Is it possible to mass modify form elements in VB Script like what can be done in Access VBA?

Posted on 2012-03-16
4
Medium Priority
?
178 Views
Last Modified: 2012-08-13
Hi everybody - Happy St. Patrick's Day Eve to ya.

Sorry in advance for writing so much, but I come from the school of thought that the more you explain at the beginning, the less confusion that's caused later on.  Of course making sense in the first place is always important.....

In Access (I have tried with 2003 and 2007), I can assign properties quickly to controls by grouping them like so:
Dim this1 as control
     For each this1 in me.form
        If Instr(1,this1.name,"start")>0 then
        this1.visible=True
        else
        this1.visible=False
        End If
     Next

Open in new window

What this does in Access (which I usually trigger via a button or an event when the form loads) is make visible all the controls in the form that have "start" as part of the name of the control.  Any control in the form that doesn't have "start" in the name will go invisible.

Does anyone know what the equivalent of this is in VB Script?  Is it even possible to do this, or something similar (I'm flexible!) to this in VB Script?  I have a pretty complex page of elements (a bunch of div "id" elements to be exact) and rather than going in and typing 4 lines of the same code for 10 different div ids, I would like to try the same thing I would do in Access and use 7 or 8 lines of code than 40 to update the form elements.  Sorry for running on with that last sentence by the way.

Is it possible to do something like the code above in VB Script?  I tried the following and VB Script doesn't like it.  Microsoft Scripting Editor errored on the For Each line and said "Object doesn't support this property or method."

dim this1
   For each this1 in document.body
     If instr(1,this1.id,"start")>0 then
       this1.style.visibility="visible"
       this1.style.display="block"
     else
       this1.style.visibility="hidden"
       this1.style.display="none"
     end if
   next

Open in new window

And I know I could nest some divs inside others to some of what I'm trying to do, but unfortunately I'm using the divs in a lot of different areas in the document's body.  I am self-taught on Access quite well, but VB Script is still something I'm learning more of as I go along.  Hopefully there's a similarity between the two when it comes to mass updating controls/elements because it would save me a lot of time writing out lines.

Thanks in advance for any help you can give.
0
Comment
Question by:Scootman78
[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
4 Comments
 
LVL 49

Expert Comment

by:Martin Liss
ID: 37731646
Which Office app are you using?
0
 

Author Comment

by:Scootman78
ID: 37731704
Sorry, I did forget to clarify that.  For the VB Script, I'm coding it directly into Notepad and the file being ran is actually a .hta file that calls a separate .vbs file.
0
 

Accepted Solution

by:
Scootman78 earned 0 total points
ID: 37738943
I actually found a solution on my own.  I pieced together my own VB Scripting knowledge  and info found on about 10 different web pages around the web that deal with For...Each statements.

In case anyone else needs to know how to "mass modify" elements in VB Script (IE 5+ Only), the code below shows you how to do it.  And I do use Javascript elsewhere in my .hta file without a problem using the code below.  My audience only uses IE, so there's no problem with me using this code:

dim ele1
    for each ele1 in document.all
       if instr(1,ele1.id,"start_")>0 then
          ele1.style.visibility="visible"
          ele1.style.display="block"
       end if
    next

Open in new window


Even though the above code is looping through my entire document, it seems to work just as fast as typing 40 lines to get the "start_" divs to appear.
0
 

Author Closing Comment

by:Scootman78
ID: 37760287
I am accepting my own solution because I solved it on my own (makes sense right?).  I appreciate the effort(s) made to help me.  I couldn't find a question or solution like I had on EE, so I had to look elsewhere.  Hopefully other EE users can benefit from this.

I'm sure there are better ways to use forms within the VB Script to keep the code from having to look through every element in the entire document.  For my needs, going through the entire document is sufficient.

And I would decrease my points to 0 if I could (I don't need points).  I'm just happy to have an answer.
0

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

649 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