|
Sending Email Using CDO and MAPI
|
Total Hit (4012) |
Sending emails via code used to be cool, but now it is a necessity. Below is code to send email via CDO. If the CDO call fails, it will send using MAPI. NOTE: You must have CDO for NT referenced in your project for this to work.
«Code LangId=1»
' Sends an email to the appropriate person(s)
'
'
....Read More |
Rating
|
|
|
Make a phone call using TAPI
|
Total Hit (4652) |
If TAPI libraries are installed on your machine, you can easily dial a number from a VB application using a single API call. Here's a function that encapsulates the call and that returns True if the dialing was successful:
«Code LangId=1»
Private Declare Function tapiRequestMakeCall Lib "TAPI32.
....Read More |
Rating
|
|
|
Always ensure that a printer is installed
|
Total Hit (2835) |
Many developers incorrectly assume that a printer is always installed on their customers' machines, and therefore omit to check that this is actually the case. The following function, deceiptively trivial, returns False and displays an error message if no printer has been installed:
«Code LangId=
....Read More |
Rating
|
|
|
Display the Connect To Printer dialog
|
Total Hit (4944) |
Under Windows NT you can programmatically display the Connect To Printer dialog using one simple API function:
«Code LangId=1»
' This works only under Windows NT and 2000
Private Declare Function ConnectToPrinterDlg Lib "winspool.drv" (ByVal hWnd As _
Long, ByVal flags As Long) As Long
....Read More |
Rating
|
|
|
Create and delete DSN at runtime
|
Total Hit (10276) |
If you're developing a VB database application, you're probably using a DSN (data source name) because it makes the access to your database file easier. Of course, when you distribuite your application, you must create the DSN.
There are some installation programs that offers the possibility to
....Read More |
Rating
|
|
|
Export DAO databases to any ISAM format
|
Total Hit (3034) |
Everyone tells you how to import, but even MS-VB techs start coughing when you ask how to export with DAO! In fact, their own documentation clearly states that it can not be done (see the note on page 314 of Jet Database Engine Programmer's Guide's "Creating an External Table").
To that statemen
....Read More |
Rating
|
|
|
|
Get the list of ODBC drivers
|
Total Hit (4230) |
The ODBCTOOL.DLL library contains three functions that make it easier to manage DSNs. To run the following code you must add a reference to the "ODBC Driver & Data Source Name Functions" library to your References dialog box. If you don't find this library listed in the References list, use the Star
....Read More |
Rating
|
|
|
Get the list of ODBC DSNs (Using ODBCTOOL.DLL)
|
Total Hit (7436) |
The ODBCTOOL.DLL library contains three functions that make it easier to manage DSNs. To run the following code you must add a reference to the "ODBC Driver & Data Source Name Functions" library to your References dialog box. If you don't find this library listed in the References list, use the Star
....Read More |
Rating
|
|
|
Read and write File ODBC data sources
|
Total Hit (4280) |
A file DSN is nothing but a text file that contains all the parameters for an ODBC connection. To prove this, just go to the default directory that holds all File DSNs (this is the \Program Files\Common Files\ODBC\Data Sources directory on Windows's boot drive) and load any .dsn file into a text edi
....Read More |
Rating
|
|
|
A dual use of a lookup query
|
Total Hit (2380) |
Usually in your application you use two different types of lookup query; the first one is for retrieving a page of records (or all records) to populate a pick list, the other one is to retrieve a single record, i.e. for decoding a code description while user is typing it in a textbox. So, if your qu
....Read More |
Rating
|
|
|
Connect a stand-alone Recordset to a database using XML
|
Total Hit (3346) |
If you are familiar with the ADO capability to create stand-alone Recordsets from the thin air, that is by adding items to their Fields collection, you're also probably aware that this feature has a serious shortcoming: you can't then connect to a database and perform any batch updates. The problem
....Read More |
Rating
|
|
|
Create explicit Field objects when looping on large Recordsets
|
Total Hit (2578) |
Whenever you access a database field through the Recordset object you incur in a slight overhead. Take for example the following code snippet:
«Code LangId=1»
Dim rs As New ADODB.Recordset
rs.Open "SELECT au_lname, au_fname FROM authors", "DSN=pubs", , , adCmdText
Do Until rs.EOF
List1.
....Read More |
Rating
|
|
|
Create UDL files the easy way
|
Total Hit (2072) |
The standard way to create a UDL file is to right-click in the directory where you want to create it and select the New-Microsoft Data Link menu command. Unfortunately, on many computers, this manual procedure won't work, because the file type "Microsoft Data Link" does not appear on the "New" menu.
....Read More |
Rating
|
|
|
Determine whether the IDE is in design, break, or run mode
|
Total Hit (2189) |
The VBIDE object model doesn't offer any native property or method to determine whether the IDE is in design-time mode, run-time mode, or debug (break) mode. However, it's easy to deduct this information by looking at the Enabled property of the menu commands in the Run top-level menu:
«Code Lang
....Read More |
Rating
|
|
|
Determine the RecordCount of a forward-only Recordset
|
Total Hit (3112) |
When working with a forward-only, read-only Recordset - that is, the default ADO Recordset - the RecordCount property always returns -1. (This can also happen with other types of server-side cursors, depending on the specific OLEDB provider.) In general, you can determine how many records were retur
....Read More |
Rating
|
|
|
Saving and restoring all IDE settings
|
Total Hit (2292) |
At times you'd like to save all the current settings of the Visual Basic environment and restore them afterwards. For example, you may want to alternate between the MDI environment with the code editor using Courier New 12 and the SDI environment with Arial 14. Or you may want to dock a different se
....Read More |
Rating
|
|
|
Where on Earth is an Add-ins's Description
|
Total Hit (2146) |
Every now and then someone asks me "How can I modify the default description that is associated to an add-in I have written and that appears in the Add-In Manager? I tried to modify the Project's Description attribute, but it didn't work".
The answer is simple, even though this detail is not doc
....Read More |
Rating
|
|
|
Determine how many records the DataReader is about to return
|
Total Hit (2172) |
The DataReader is the ADO.NET counterpart of the forward-only, read-only recordset in classic ADO. For this reason you never know how many rows the DataReader is about to return. In most cases you don't need this information, because you tipically process each row as soon as it is being returned, an
....Read More |
Rating
|
|
|
A better beep
|
Total Hit (3946) |
If you aren't satisfied with the standard Beep command (who is?) you can use the Beep API function instead, that lets you control both the frequency (in Hertz) and the duration (in milliseconds) of the beep. Note that you need an aliased Declare to avoid a name conflict with the VB command:
«Code
....Read More |
Rating
|
|
|
Register and unregister components with context menus
|
Total Hit (3197) |
The stardard method to register and unregister ActiveX component is running the REGSVR32 utility, which forces you to bring up the Start|Run dialog and manually type the command line. A much better approach is to have the Register and Unregister commands right in the context menu that appears when y
....Read More |
Rating
|
|
|
Register and unregister type libraries
|
Total Hit (3595) |
All COM-oriented VB developers know how to register and unregister an ActiveX DLL, using the REGSVR32 utility. However, there is no such an utility to register and unregister a type library.
You can quickly build your own TLB Registration utility with a handful of statements, thanks to the undoc
....Read More |
Rating
|
|
|
Saving a MSChart image to file
|
Total Hit (5801) |
To save to file the graph generated by a MSChart control, you must use the control’s EditCopy method to copy the image into the clipboard, and then paste it into a PictureBox control. Then, just use the SavePicture function to save the PictureBox’s content to file. Here’s an example:
«Code LangId
....Read More |
Rating
|
|
|
Understanding interface marshaling
|
Total Hit (3589) |
There is quite a lot of misunderstanding among COM newbies about what really happens when a COM interface is passed as a method parameter. As in most of the cases, VB programmers are protected from a lot of details on the COM run-time, but you do have to know such details if you want to assemble som
....Read More |
Rating
|
|
|
Combine Default attribute with other attributes
|
Total Hit (3248) |
When building an ActiveX control, you can set a default property or method using the Procedure Attributes dialog box, after clicking on the Advanced button. However, if your default property also happens to require another special attribute - as is the case with Caption and Text properties-you're in
....Read More |
Rating
|
|
|
Detect when a new control is added to an ActiveX container
|
Total Hit (2656) |
You can easily create ActiveX controls that work as containers for other controls, by setting their ControlContainer property to True. However, VB doesn't offer any event for detecting when the programmer adds or remove controls to the ActiveX control, after placing it on a form's surface.
It's p
....Read More |
Rating
|
|
|
|
Count number of words with the RegExp object
|
Total Hit (3775) |
A Visual Basic function that counts the number of words in a sentence or text file can become quickly very complex, and usually doesn't execute fast enough for most purposes. Thanks to the RegEx object that comes with the Microsoft VBScript Regular Expression type library, this task becomes trivial.
....Read More |
Rating
|
|
|
Create a better InStr function with VBScript regular expressions
|
Total Hit (14960) |
Regular expressions offer an extremely powerful way to search and replace text inside a string using sophisticated search criteria, far behind the capabilities of VB's InStr and Replace functions. For example, you can search for whole words, or find a match with a range of characters (for example, a
....Read More |
Rating
|
|
|
Send HTML Email via CDO
|
Total Hit (4043) |
Ever wonder how to send email that looks like a web page? Here is how you do it. Note: You must have CDO for NT referenced for this to work.
«Code LangId=1»
'Sends an email to the appropriate person(s).
'
'From = Email address being sent from
'SendTo = List of email addresses separated by a s
....Read More |
Rating
|
|