Blog

This is quite old so I don't know if its still correct.  I am copying over notes from elsewhere.

 

Sybase DB connection in Outlook
sub getDBresult()

Set SYBConn = Item.Application.CreateObject("ADODB.Connection")
SYBConn.Open "Data Source=NY_GCREDIT_DEV2;UID=mpedba;PWD=mpedba"

Set objRS = SYBConn.Execute("select count(*)as Total from mpe..automated_top_cpty")
msgbox(objRS("Total"))
set objRS=nothing
set SYBConn=nothing
end sub



Getting the password for an Outlook form is an almost trivial exercise, because the FormDescription object, which contains key information about the form, includes a Password property. The Outlook 2000 VBA code below pops up the value of the Password property in a message box. Before running it, open an item that uses the custom form. You can either open an existing item or use the File, New, Choose Form command to create a new item using the custom form. You can then press Alt+F8 to display the Macros dialog box and choose the GetFormPassword macro.
===================================

Sub GetFormPassword()
    Dim objApp As Application
    Dim objInsp As Inspector
    Dim objFD As FormDescription
 

    Set objApp = CreateObject("Outlook.Application")
    Set objInsp = objApp.ActiveInspector
    If Not objInsp Is Nothing Then
        Set objFD = objInsp.CurrentItem.FormDescription

        MsgBox _
          Prompt:="The password for the " & _
                  Chr(34) & objFD.MessageClass & _
                  Chr(34) & " form is:" & _
                  vbCrLf & vbCrLf & objFD.Password, _
          Title:="Get Form Password"
 

    Else

        MsgBox _
          Prompt:="Please open an item using " & _
                  "the desired form before you " & _
                  "run the GetFormPassword macro.", _
          Title:="Get Form Password"

    End If
 
 

    Set objFD = Nothing
    Set objNS = Nothing
    Set objApp = Nothing

End Sub



Adding Carriage Returns
When writing code that exports to a plain text file, it's often necessary to embed special characters, such as carriage returns, line feeds, and tab characters. VB has special constants defined for many of these characters:
vbTab - Tab character vbLf - Line feed vbCr - Carriage Return vbCrLf - Carriage return/line feed combination
These constants are available in VB 6 and I believe they are also available in VB 5. Prior to that, I don't remember. However, you can easily substitute the control code using the Chr (or Chr$) function:
vbTab = Chr(9)
vbLf = Chr(10)
vbCr = Chr(13)
vbCrLf = Chr(13) & Chr(10)


PropertyChange and CustomPropertyChange
You can use the PropertyChange and CustomPropertyChange events to help you understand what happens when the user interacts with form controls showing both built-in and custom properties. Just add this code to your form to have a message box pop up every time a property changes. (For example, guess how many properties change when you change the status of a task to Completed.)
Sub Item_PropertyChange(ByVal Name)
MsgBox "The " & Name & " property changed."
End Sub
Sub Item_CustomPropertyChange(ByVal Name)
MsgBox "The " & Name & " custom property changed."
End Sub


Combo Boxes
Property  Description

BackColor  The combo box's background color.
ForeColor  The combo box's foreground text color.
Height   The height, in twips, of the closed combo box.
IntegralHeight  Determines whether the combo box can display partial items, such as the upper half of an item that falls toward the bottom of the combo box.
List   A drop-down property list box in which you can enter values into the combo box at design time. You can enter only one at a time, and most      programmers prefer to initialize the combo box at runtime.
Sorted   Determines whether the combo box values are automatically sorted. If False (the default value), the values appear in the same order in which the program    added the items to the combo box.
Style   Determines the type of combo box your application needs. If 0-DropDown Combo, the combo box is a drop-down combo box. If 1-Simple Combo, the     combo box turns into a simple combo box that remains open to the height you use at design time. If 2-DropDown List, the combo box turns into    a drop-down list box that remains closed until the user is ready to see more of the list.



ListBox Properties
Property  Description

BackColor  Specifies the list box's background color.
Columns  Determines the number of columns. If 0, the list box scrolls vertically in a single column. If 1 or more, the list box items appear in the number of columns    specified (one or more columns) and a horizontal scrollbar appears so you can see all the items in the list.
ForeColor  Specifies the list box's text color.
Height   Indicates the height of the list box in twips.
IntegralHeight  Determines whether the list box can display partial items, such as the upper half of an item that falls toward the bottom of the list box.
List   Holds, in a drop-down property list box, values that you can enter into the list box at design time. You can enter only one at a time, and most     programmers usually prefer to initialize the list box at runtime.
MultiSelect  The state of the list box's selection rules. If 0-None (the default), the user can select only one item by clicking with the mouse or by pressing the     Spacebar over an item. If 1-Simple, the user can select more than one item by clicking with the mouse or by pressing the Spacebar over items    in the list. If 2-Extended, the user can select multiple items using Shift+click and Shift+arrow to extend the selection from a previously selected    item to the current one. Ctrl+click either selects or deselects an item from the list.
Sorted   Determines whether the list box values are automatically sorted. If False (the default value), the values appear in the same order in which the program     added the items to the list.
Style   Determines whether the list box appears in its usual list format or, as shown in Figure 10.3, with check boxes next to the selected items.

Common list box methods.

Method   Description

AddItem  Adds a single item to the list box.
Clear   Removes all items from the list box.
List   A string array that holds items from within the list box.
ListCount  The total number of list box items.
RemoveItem  Removes a single item from the list box.

Perhaps the most important method is the AddItem method, which adds items to the list box. AddItem is to list boxes what the assignment statement is to variables. A method always appears between the control name and a period. For example, the following AddItem method sends the value of Joseph to a list box named lstOneCol:
lstOneCol.AddItem "Joseph"



Do While (comparison test)
   Block of one or more Visual Basic statements
Loop

Do Until (comparison test)
   Block of one or more Visual Basic statements
Loop

Do
   Block of one or more Visual Basic statements
Loop Until (comparison test)



if/else/case
If (txtSales.Text > 5000.00) Then
   sngBonus = .05 * txtSales.Text
Else
      if (Moon = "blue cheese") Then
 pigs = "fly"
      Else
 curPayAmt = curPayAmt - 25.00
End If
curTaxes = curPayAmt * .42

======================================

Select Case intAge
   Case 5:  lblTitle.Caption = "Kindergarten"
   Case 6:  lblTitle.Caption = "1st Grade"
   Case 7:  lblTitle.Caption = "2nd Grade"
   Case 8:  lblTitle.Caption = "3rd Grade"
   Case 9:  lblTitle.Caption = "4th Grade"
   Case 10: lblTitle.Caption = "5th Grade"
   Case 11: lblTitle.Caption = "6th Grade"
   Case Else:  lblTitle.Caption = "Advanced"
End Select



Alert Boxes
anIntVariable = MsgBox( strMsg [, [intType] [, strTitle]])
e.g.
Dim anIntVariable
anIntVariable = MsgBox("hello", vbYesNoCancel, "Test Alert!")
 
NOTE: The MsgBox() function's format shown here accepts one required (strMsg) and two optional (intType and strTitle) arguments. MsgBox() can accept more arguments, but these three are the only ones needed in most applications.

strMsg is a string (either a variable or a string constant enclosed in quotation marks) and forms the text of the message displayed in the message box. intType is an optional numeric value or expression that describes the options you want in the message box. Table 6.1, Table 6.2, and Table 6.3 contain all the possible values you can use for the type of message box you want displayed. (Visual Basic displays no icon if you don't specify an intType value.) If you want to use a value from two or more of the tables, you'll add the values together. Although you can use the integer value, if you use the built-in Visual Basic named literal, you'll more easily understand the message box's style if you ever have to change the message box in the future. strTitle is an optional string that represents the text in the message box's title bar. If you omit strTitle, Visual Basic uses the project's name for the message box's title bar text.
Table 6.1. The buttons displayed in a message box.
Named Literal Value Description
vbOKOnly 0 Displays the OK button.
vbOKCancel 1 Displays the OK and Cancel buttons.
vbAbortRetryIgnore 2 Displays the Abort, Retry, and Ignore buttons.
vbYesNoCancel 3 Displays the Yes, No, and Cancel buttons.
vbYesNo 4 Displays the Yes and No buttons.
vbRetryCancel 5 Displays the Retry and Cancel buttons.
 

Table 6.2. The icons displayed in a message box.
Named Literal Value Description
vbCritical 16 Displays Critical Message icon.
vbQuestion 32 Displays Warning Query icon.
vbExclamation 48 Displays Warning Message icon.
vbInformation 64 Displays Information Message icon.
 

Table 6.3. The default buttons displayed in a message box.
Named Literal Value Description
vbDefaultButton1 0 The first button is the default.
vbDefaultButton2 256 The second button is the default.
vbDefaultButton3 512 The third button is the default.
 

Table 6.4. MsgBox() return values.
Named Constant Value Description
vbOK 1 The user clicked the OK button.
vbCancel 2 The user clicked the Cancel button.
vbAbort 3 The user clicked the Abort button.
vbRetry 4 The user clicked the Retry button.
vbIgnore 5 The user clicked the Ignore button.
vbYes 6 The user clicked the Yes button.
vbNo 7 The user clicked the No button.



maths operators

Operator  Example   Description

+   Net + Disc   Adds two values
-   Price - 4.00   Subtracts one value from another value
*   Total * Fact   Multiplies two values
/   Tax / Adjust   Divides one value by another value
^   Adjust ^ 3   Raises a value to a power
& (or +)  Name1 & Name2  Concatenates two strings



casting numeric values

Although Visual Basic normally takes care of data types when you type number values, you might need to ensure that Visual Basic interprets a numeric literal as one of the specific numeric data types. For example, you might type the literal 86 and need Visual Basic to store or display the value as a Long data type even though 86 fits within a Byte or Integer data type.

You can use the data type suffix characters from Table 5.2 to override the default data type. The suffix characters let you specify the data type for numeric literals when you need to. Occasionally, Visual Basic will also use the data type suffix characters when displaying numeric information. Therefore, if you type 86#, Visual Basic treats the number 86 as a double-precision value.

Suffix Character  Data Type  Example
&    Long   86&
!    Single   86!
#    Double   86#
@    Currency  86@



datatype prefixes

Prefix   Data Type  Example

bln   Boolean  blnIsOverTime
byt   Byte   bytAge
cur   Currency  curHourlyPay
dtm   Date   dteFirstBegan
dbl   Double   dblMicroMeasurement
int   Integer   intCount
lng   Long   lngStarDistance
obj   Object   objSoundClip
sng   Single   sngYearSales
str   String   strLastName
vnt or var  Variant   vntControlValue



Data Type  Description and Range

Boolean  A data type that takes on one of two values only: True or False. True and False are Visual Basic reserved words, meaning that you cannot use them for    names of items you create.
Byte   Positive numeric values without decimals that range from 0 to 255.
Currency  Data that holds dollar amounts from -$922,337,203,685,477.5808 to $922,337,203,685,477.5807. The four decimal places ensure that proper rounding    can occur. VB respects your Windows International settings and adjusts currency amounts according to your country's requirements. Never     include the dollar sign when entering Currency values.
Date   Holds date and time values. The date can range from January 1, 100, to December 31, 9999. (In the years following 9999, people will have to use     something other than Visual Basic!)
Decimal  A new data type not yet supported in Visual Basic except in a few advanced situations. The Decimal data type represents numbers with 28 decimal     places of accuracy.
Double   Numeric values that range from -1.79769313486232E+308 to 1.79769313486232E+308. The Double data type is often called double-precision.
Integer   Numeric values with no decimal point or fraction that range from -32,768 to 32,767.
Long   Integer values with a range beyond that of Integer data values. Long data values range from -2,147,483,648 to 2,147,483,647. Long data values consume    more memory storage than integer values, and they are less efficient. The Long data type is often called long integer.
Object   A special data type that holds and references objects such as controls and forms.
Single   Numeric values that range from -3.402823E+38 to 3.402823E+38. The Single data type is often called single-precision.
String   Data that consists of 0 to 65,400 characters of alphanumeric data. Alphanumeric means that the data can be both alphabetic and numeric. String data    values may also contain special characters such as ^, %, and @. Both fixed-length strings and variable-length strings exist.
Variant   Data of any data type and used for control and other values for which the data type is unknown.



Form Property  Description

BackColor  Specifies the form's background color. Click the BackColor's palette down arrow to see a list of colors and click Categorized to see a list of common     Windows control colors.
BorderStyle  Determines how the Form window appears. The BorderStyle property specifies whether the user can resize the form and also determines the kind of form    you wish to display.
Caption  Displays text on the form's title bar at runtime.
ControlBox  Determines whether the form appears with the Control menu icon. The Control menu appears when your application's user clicks the Control menu icon.
Enabled  Determines whether the form is active. Often, you'll change the Enabled property at runtime with code when a form is no longer needed. Generally, only    multiform applications, such as MDI applications, need to modify a form's Enabled property.
Font   Produces a Font dialog box in which you can set the text's font name, style, and size.
ForeColor  Holds the color of the form's text.
Height   Holds the height of the form's outline in twips.
Icon   Describes the icon graphic image displayed on the taskbar when the user minimizes the form.
Left   Holds the number of twips from the form's left edge to the screen's left edge.
MaxButton  Specifies whether a maximize window button appears on the form.
MinButton  Specifies whether a minimize window button appears on the form.
MousePointer  Determines the shape of the mouse cursor when the user moves the mouse over the form.
Moveable  Specifies whether the user can move the form at runtime.
Picture   Determines a graphic image that appears on the form's background at runtime.
ScaleMode  Determines whether the form's measurements appear in twips, pixels (the smallest graphic dot image possible), inches,
   centimeters, or other measurements.
ShowInTaskbar  Determines whether the form appears on the Windows taskbar.
StartUpPosition Determines the state (centered or default) of the form at application startup.
Top   Holds the number of twips from the form's top edge to the Form window's top edge.
Visible   Determines whether the form appears or is hidden from the user.
Width   Holds the width of the form in twips.
WindowState  Determines the initial state (minimized, maximized, or normal) in which the window appears at runtime.



TextBoxProperty  Description

Alignment  Determines whether the text box's text appears left-justified, centered, or right-justified within the text box's boundaries.
BackColor  Specifies the text box's background color. Click the BackColor property's palette down arrow to see a list of colors and click Categorized to see a list of    common Windows control colors.
BorderStyle  Determines whether a single-line border appears around the text box.
Enabled  Determines whether the text box is active. Often, you'll change the Enabled property at runtime with code when a text box is no longer needed.
Font   Produces a Font dialog box in which you can set the Text property's font name, style, and size.
ForeColor  Holds the color of the text box's text.
Height   Holds the height of the text box's outline in twips.
Left   Holds the number of twips from the text box's left edge to the Form window's left edge.
Locked  Determines whether the user can edit the text inside the text box that appears.
MaxLength  Specifies the number of characters the user can type into the text box.
MousePointer  Determines the shape of the mouse cursor when the user moves the mouse over the text box.
MultiLine  Lets the text box hold multiple lines of text or sets the text box to hold only a single line of text. Add scrollbars if you wish to put text in a multiline text    box so your users can scroll through the text.
PasswordChar  Determines the character that appears in the text box when the user enters a password
   (keeps prying eyes from knowing what the user enters into a text box).
ScrollBars  Determines whether scrollbars appear on the edges of a multiline text box.
TabIndex  Specifies the order of the text box in the focus order.
TabStop  Determines whether the text box can receive the focus.
Text   Holds the value of the text inside the text box. The Text property changes at runtime as the user types text into the text box. If you set an initial Text     property value, that value becomes the default value that appears in the text box when the user first sees the text box.
ToolTipText  Holds the text that appears as a tooltip at runtime.
Top   Holds the number of twips from the text box's top edge to the Form window's top edge.
Visible   Determines whether the text box appears or is hidden from the user.
Width   Holds the width of the text box in twips.



Label Property  Description

Alignment  Determines whether the label's caption appears left-justified, centered, or right-justified within the label's boundaries.
AutoSize  Enlarges the label's size properties, when True, if you assign a caption that is too large to fit in the current label's boundaries at runtime.
BackColor  Specifies the label's background color. Click the BackColor's palette down arrow to see a list of colors and click Categorized to see a list of common     Windows control colors.
BackStyle  Determines whether the background shows through the label or if the label covers up its background text, graphics, and color.
BorderStyle  Determines whether a single-line border appears around the label.
Caption  Holds the text that appears on the label.
Enabled  Determines whether the label is active. Often, you'll change the Enabled property at runtime with code when a label is no longer needed.
Font   Produces a Font dialog box in which you can set the caption's font name, style, and size.
ForeColor  Holds the color of the label's text.
Height   Holds the height of the label's outline in twips.
Left   Holds the number of twips from the label's left edge to the Form window's left edge.
MousePointer  Determines the shape of the mouse cursor when the user moves the mouse over the label.
TabIndex  Specifies the order of the label in the focus order. Although the label cannot receive the direct focus, the label can be part of the focus order.
ToolTipText  Holds the text that appears as a tooltip at runtime.
Top   Holdsthe number of twips from the label's top edge to the Form window's top edge.
Visible   Determines whether the label appears or is hidden from the user.
Width   Holds the width of the label in twips.
WordWrap  Determines whether the label expands to fit whatever text appears in the caption.



Cmd Btn Property  Description

BackColor  Specifies the command button's background color. Click the BackColor's palette down arrow to see a list of colors and click Categorized to see a list of common  Windows control colors. Before the command button displays the background color, you must change the Style property from 0-Standard to 1-Graphical.
Cancel   Determines whether the command button gets a Click event if the user presses Esc.
Caption  Holds the text that appears on the command button.
Default   Determines if the command button responds to an Enter keypress even if another control has the focus.
Enabled  Determines whether the command button is active. Often, you'll change the Enabled property at runtime with code when a command button is no longer needed and you want to gray out the command button.
Font   Produces a Font dialog box in which you can set the caption's font name, style, and size.
Height   Holds the height of the command button in twips.
Left   Holds the number of twips from the command button's left edge to the Form window's left edge.
MousePointer  Determines the shape of the mouse cursor when the user moves the mouse over the command button.
Picture   Holds the name of an icon graphic image that appears on the command button as long as the Style property is set to 1-Graphical.
Style   Determines whether the command button appears as a standard Windows command button (if set to 0-Standard) or a command button with a color and possible picture (if set to 1-Graphical).
TabIndex  Specifies the order of the command button in the focus order.
TabStop  Determines whether the command button can receive the focus.
ToolTipText  Holds the text that appears as a tooltip at runtime.
Top   Holds the number of twips from the command button's top edge to the Form window's top edge.
Visible   Determines whether the command button appears or is hidden from the user. (Invisible controls cannot receive the focus until the running code changes the Visible property to True.)
Width   Holds the width of the command button in twips.



Prefix  Control
 
cbo  Combo box
chk  Check box
cmd Command button
dir  Directory list box
drv  Drive list box
fil  File list box
fra  Frame
frm  Form
grd  Grid
hsb  Horizontal scrollbar
img  Image
lbl  Label
lin  Line
lst  List box
mnu  Menu
ole  OLE client
opt  Option button
pic  Picture box
shp  Shape
tmr  Timer
txt  Text box
vsb  Vertical scrollbar


Why do I get the following error - ActiveX component can't create Object: 'Outlook.Application' or a similar error regarding Act!
 
Internet Explorer is unable to start Microsoft Outlook. Verify your installation.
If Microsoft Outlook runs properly on your machine, you may need to change your Internet Explorer security settings.

Click Tools|Internet Options and then Security. Click the Internet zone and then click the Custom Level button. Select Prompt for the Initialize and script ActiveX Controls setting. Click OK. You will be prompted just before Microsoft Outlook initializes.

Please be aware that you will get the same prompt if you come across ActiveX Controls on other web sites.