Access Cookbook - Ken Getz [210]
To use this technique in your own applications, follow these steps:
Identify the shared database you'll be using to hold the messages. This can be an existing shared database or a new one designed expressly for this purpose. Create a new table with the fields shown in Table 10-5. Make MessageID the primary key of this table, and save it as tblMessage.
Table 10-5. Fields in tblMessage
Field name
Data type
MessageID
AutoNumber
From
Text
To
Text
DateSent
Date/Time
DateReceived
Date/Time
Message
Memo
Close the shared database and open the database with which you want to send and receive messages. This is the database where you'll create the remaining objects. Import basMail and basFillUsers from 10-04fe.MDB to this database.
Create a new form with the properties shown in Table 10-6.
Table 10-6. Properties for frmSendMail
Property
Value
Caption
Send Mail
DefaultView
Single Form
ScrollBars
Neither
RecordSelectors
No
NavigationButtons
No
Add two unbound text box controls and an unbound combo box control to the form, as shown in Figure 10-17. Name the first text box txtFrom. Set its ControlSource property to:
=CurrentUser( )
Name the second text box txtMessage and size it to hold the text of your message. Set the EnterKeyBehavior property for txtMessage to New Line in Field.
Name the combo box cboTo and size it the same as txtFrom. Set its combo box-specific properties to match those in Table 10-7.
Table 10-7. Properties for the cboTo combo box
Property
Value
RowSourceType
acbFillUserList
RowSource
ColumnCount
1
ColumnHeads
No
ColumnWidths
BoundColumn
1
ListRows
8
ListWidth
Auto
Add a command button to the form, with the properties shown in Table 10-8. The &Send Message caption makes the button respond to the Alt-S accelerator key shortcut.
Table 10-8. Properties for cmdSend
Property
Value
Name
cmdSend
Caption
&Send Message
OnClick
=acbSendMail( )
Save this form as frmSendMail.
Select File → Get External Data → Link Tables and link the tblMessage table you created in your shared database to this frontend database.
Create a new query based on tblMessage. Drag all the fields from the field list to the query grid. Set the query criteria as shown in Table 10-9. Save this query as qryNewMail.
Table 10-9. Criteria for qryNewMail
Field
Criteria
To
CurrentUser( )
DateReceived
Is Null
Create another new form, with the properties shown in Table 10-10.
Table 10-10. Properties for frmReceiveMail
Property
Value
RecordSource
qryNewMail
Caption
No mail
DefaultView
Single Form
AllowAdditions
No
ScrollBars
Neither
RecordSelectors
No
NavigationButtons
Yes
OnLoad
=acbCheckMail( )
OnTimer
=acbCheckMail( )
TimerInterval
10000
Add three bound text box controls to the form. Name the first one txtFrom, set the ControlSource to From, and size it to hold the sender's address. Name the second one txtSent, set the ControlSource to DateSent, and size it to hold the date and time the message was sent. Name the third one txtMessage, set the ControlSource to Message, and size it to hold the message text.
Add a watermark picture to the form using the additional form properties found in Table 10-11.
In the sample database, we've used a simple bitmap created with the Windows Paint program to display a message in the center of the form. This bitmap, NONEW.BMP, is included on the CD-ROM. (CD content is available online at http://examples.oreilly.com/accesscook.) You can add this bitmap to your form or create your own.
Table 10-11. Additional properties for frmReceiveMail
Property
Value
Picture
bitmap file
PictureType
Embedded
PictureSizeMode
Clip
PictureAlignment
Center
PictureTiling
No
Place a Rectangle control with the same background color as the form's detail section behind all of the controls on the form. After you have positioned it and sized it to take up the entire detail section, you can move it behind