Special Edition Using Microsoft Office Outlook 2003

Many companies use Microsoft Access or SQL Server to store contact or product information. You can use Outlook custom forms to take information from or write information to a database using ADO (ActiveX Data Objects). In the following example, information from the Frame Order System is transferred to an Access database for reporting purposes:

Sub cmdSubmit_Click() Dim objConnection Dim objRecordset Dim strSQL Set objConnection = CreateObject("ADODB.Connection") objConnection.Mode = 3 objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data_ Source=\\server\f\Frames.mdb;" strSQL = "SELECT * FROM FrameInformation;" Set objRecordset = CreateObject("ADODB.Recordset") objRecordset.Open strSQL, db2,2,3 objRecordset.AddNew objRecordset.Fields("CustomerName") = Item.UserProperties("CustomerName") objRecordset.Fields("CustomerCode") = Item.UserProperties("CustCode") objRecordset.Fields("CreationDate") = Item.UserProperties("CreationDate") objRecordset.Fields("OrderNumber") = Item.UserProperties("OrderNumber") objRecordset.Fields("SalesRep") = Item.UserProperties("SalesRep") objRecordset.Fields("Status") = Item.UserProperties("Status") objRecordset.Update objRecordset.Close objConnection.Close Set objRecordset = Nothing Set objConnection = Nothing End Sub

Using the same type of code, you can transfer information from an Access database to a custom form. Using ADO to transfer information to or from a database can give your custom forms greater power and enable you to back up and retrieve data from your database at any time.

Категории