Naming Conventions For Objects
VBA vs. Visual Basic
Chapter 4: VBE- the UserForm Interface
The Visual Basic Editor (VBE) platform can be accessed by:
The VBE gives you a tree-structured view of all the application with its associated objects. You can expand these and collapse branches of the views to get more or less detail. The VBE window displays UserForms, modules or other separators. If you want to select a UserForm or module, simply double click on the project explorer window for a more detailed look.
A UserForm is a custom dialog, a pop-up window that collects and processes input from the user. It looks and acts just like any of the familiar built-in dialogs, such as the ones you see when you click File à Print or Format à Font, except that you design it yourself and tailor its elements to suit the needs of the job it performs through the use of programming language- VBA.
Userforms and the VBA language are also seen in other MS Office programs, including Excel and PowerPoint. Not only do these programs use many of the same fundamental principles, some of the best references that have solved problems for me in the Word platform have come from Excel internet and book sources.
Userforms can employ any number of available graphical "controls" — command buttons, text boxes, check boxes, list boxes, option buttons ("radio buttons"), scroll bars, and multi-page structures. Learning about all of them, and how to write the VBA code that lives inside them is critical to unleashing the power of Word as an EMR. Making a simple UserForm, though, is not difficult.
The Toolbox Objects
When you click on the Toolbar’s View à Toolbox the following form appears with available controls:
Each of these controls have specific properties as demonstrated in the “Properties Window”, including size, color, font, and other elements that could be manipulated. Passing your pointer over the specific properties gives a brief description on what can be altered.
Naming Conventions For Objects
Object names should follow a certain standard, as displayed below, with a 3 letter code followed by a capital letter and then the rest of the object name.
LABELS: generally are in all caps
Creating Your First UserForm
To create your first basic UserForm that houses a macro which performs an activity in Word, follow these steps:
When you create a new document from the template, the "autonew" macro opens the user form for the user to input data, then when the command button is clicked, the code associated with that button inserts each piece of information into the respective bookmark. Alternatively, you can place a new toolbar item to allow for UserForm access at anytime.
The end-user now only has to add text to the textbox, then deploy the text onto the bookmark that you previously had placed onto your template. There's lots more that you can do with UserForms. If you get stuck, post a question to the microsoft.public.word.vba.userforms newsgroup and someone will spring to your rescue.
VBA vs. Visual Basic
In the next few chapters we'll be discussing topics dealing with the underlying coding of your project. It's important to understand the difference between VB and VBA. Visual Basic (VB) is the programming language of choice for programmers that work in the Windows OS environment. It is a programming language that can be compiled to create standalone exe's and ActiveX dll's. VBA (VBA) is a subset of VB that is used as a macro language for MS Office (as well as some other programs like AutoCad). VBA is not capable of creating a standalone executable, but rather is ran within the host environment of the parent program (Excel, Word, Access, etc.)
The VB programming language has been chosen by the many due to its ease of use. With little extra work, a VB programmer can write Windows programs without having to relearn how to program in a different language syntax, for example Visual C++. Visual Basic programs are free standing Windows programs which can be compiled and exported to other Windows platform. VB programs run in their own memory space inside MS Windows. They can even run on RISC platforms running on Windows without changing any of the existing programs.
VB also allows programmers to make Custom Controls to be used in other Visual Basic program, as well as Delphi and Visual C++. Using VB Enterprise, programmers can create n-tiered systems. This allows programmers to create programs that communicate with each other across a network to share information and resources as well as work in unison. This is useful in splitting the client and server processing thus speeding data access for users.
VBA provides a complete integrated development environment (IDE) that features the same elements familiar to developers using Microsoft Visual Basic, including a Project Window, a Properties Window, and debugging tools. VBA is finding its way into more and more applications, including the popular MS Office System. Since VBA is actually a part of the application the overhead is lower which makes accessing and manipulating the host application faster. It also gives users greater ability to manipulate the host application objects.
Applying this Tutorial to Your EMR Project
At this point, begin creating your UserForms, pasting the various objects that you will need to most rapidly fill in the patient chart. Don’t worry about the underlying code just yet. Typical UserForms include:
As you develop your EMR project
, you will find that you will need many more UserForms and subforms.