|
Sending Email Using CDO and MAPI
|
Total Hit (4092) |
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 (4785) |
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 (2902) |
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 (5041) |
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
|
|
|
Printing formatted text and other data with the WebBrowser control
|
Total Hit (2285) |
Printing con be quite difficult in VB.NET (or any other .NET language), especially if you not only have to print plain text, but also tables, images, bulleted lists, text with different fonts, styles, colors and any other type of formatted data. Here's a tip that can make your life much easier, in m
....Read More |
Rating
|
|
|
Create and delete DSN at runtime
|
Total Hit (10613) |
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 (3096) |
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 (4290) |
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 (7626) |
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 (4370) |
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 (2430) |
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 (3407) |
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 (2642) |
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 (2132) |
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
|
|
|
Calculated columns that refer to relationships
|
Total Hit (2988) |
The DataSet is a container of multiple DataTables, and it allows to create parent-child relationships between two tables, as shown below:
«Code LangId=2»
' create a relationship between the Categories and the Products tables,
' against the CatID column
ds.Relations.Add(New DataRelation("CatPr
....Read More |
Rating
|
|
|
Pass the hidden Global object to an ActiveX DLL
|
Total Hit (3193) |
An ActiveX DLL doesn't have direct access to the environment of the calling EXE. For example, the App and Printer objects in the DLL don't correspond to the objects with the same name in the main application, therefore if you want to print something from the DLL using the same settings as the main a
....Read More |
Rating
|
|
|
Programmatically register an ActiveX control or DLL
|
Total Hit (4961) |
All ActiveX DLL or OCX export two functions: DllRegisterServer and DllUnregisterServer. They are used to register and unregister the ActiveX in the Windows registry, and are usually invoked from regsvr32.exe at registration time.
However, you can register and unregister these files programmatical
....Read More |
Rating
|
|
|
Rebase compiled DLLs
|
Total Hit (3344) |
Many VB developers know that they should specify a DLL Base Address value - in the Compile tab of the Project Properties dialog box - that is different from the base address of any other DLL or OCX used in the project.
When you are working with a compiled DLL or OCX for which you don't have the
....Read More |
Rating
|
|
|
Register and unregister components with context menus
|
Total Hit (3310) |
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 (3674) |
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 (5897) |
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 (3672) |
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
|
|
|
Release COM objects earlier
|
Total Hit (2981) |
If you're using a COM object through COM Interop you should be aware that the object isn't released as soon as you set it to Nothing, as it happens with VB6. Instead, the object will be released only at the first garbage collections that occurs after the object is set to Nothing or goes out of scope
....Read More |
Rating
|
|
|
Combine Default attribute with other attributes
|
Total Hit (3327) |
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 (2729) |
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 (3846) |
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 (15287) |
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 (4156) |
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
|
|