Learn Microsoft Access Advanced Programming Techniques, Tips and Tricks.

Attachment Field in Access2007

Working with images or animations in Applications like MS-Access was always fun.  I have used Office Assistant for Message Boxes in all my Microsoft Access Applications by creating and installing common VBA library programs on the network.

I don't know how many of you know that you can display your own custom images in the Office Assistant control.  I have used this feature to display custom made greetings to my MS-Access Application Users on special occasions like Christmas, Eid, Onam etc. by simply replacing a company logo image (used for normal display in the message box) on the Server.  I am totally disappointed when Microsoft discarded this feature from Microsoft Office 2007.

Those who are still using Microsoft Access2003 or earlier versions can check the following links for tricks with Office Assistant for MsgBox:

The Attachment Field type in Access2007 gives much needed flexibility in storing several external documents or images in one record without inflating the database size, as it does with Object Linking and Embedding (OLE) method widely used in earlier version of Access for storing/editing/displaying images. Hyperlinks in a data field can be used for linking only one external file or any one internal object like Form or Report.

Attachment Field gives much needed advantage in storing and retrieving important documents like Project site plans, diagrams, Contract Agreements, Engineering Drawings, employees’ family photos or whatever related to a particular record in the database.  The attached document or image can be edited in its own native Application.

  1. Open Microsoft Access2007.
  2. If you have already created the Northwind 2007.accdb sample database then open it; otherwise select Local Templates from the Template Categories.
  3. Click on the Northwind 2007 Template to select it.
  4. Click on the Folder icon at the right side of the File Name control and select the required folder to save the Northwind 2007.accdb database.
  5. Click on the Create Command Button to create the sample database and open it.
  6. Close the Home Form.
  7. Select Object Type from the drop down list in the Navigation Pane and select Tables.
  8. Right-click on the Employees table and select Design View from the Shortcut Menu.
  9. Use the right scroll bar to move the field list up and bring the last field Attachments with field type Attachment into view.
  10. Now that we have seen the Attachment Field in Employees Table (or you can create a new Table with the Attachment Field, if you prefer) close the design view.
  11. Open the Employees Table in Datasheet View.
  12. Move the horizontal scroll bar and bring the attachment field into view, see the sample image shown below:
  13. The second column (highlighted) is the attachment field where a paper clip image and a number in brackets (zero) showing how many attachments are there in each record.
  14. There are no attachments added in any of those record so far, so we will do that; double-click in the attachment field of the first record.
  15. The Attachment control opens up. Click on the Add… Command Button to browse for files on the hard disk. You may select a Word Document, Excel File, PDF file or Image.
  16. Repeat this action to attach more files into the same field.
  17. Click OK to close the dialog box.  You will now see a number appearing in brackets indicating how many attachments are there in that field of the record.
  18. Double-click on the attachment field to open and show the attached files.
  19. Click on one of the files to select it.
  20. If you click on the Remove Command Button you can remove the selected attachment or click Open to open the document in its parent/preview Application.
  21. If you right-click on the attachment field the Manage Attachment shortcut menu is displayed.  Selecting this option will open up the earlier dialog box we have seen for attaching/removing/opening external files.
Technorati Tags:
Share:

PrimaryKey usage with Many Fields

When Microsoft Access Tables are designed, or Tables in any database systems for that matter, especially the master table, the first thing we consider is  to maintain uniqueness of at least one field contents for easier retrieval of information.  For example: Employee Codes in Employees Table in the Northwind.mdb sample database. Each employee is identified with a unique code number, but who will check for the uniqueness of the numbers entered into the employee-code field.  We can validate User inputs for uniqueness with VBA programs before storing them into the table.  But, this is already built into the database systems and used in the form of  PrimeryKey Index.  This not only prevents from entering duplicate values into this field but also arranges the data in Ascending/Descending order.

We can use this field values in programs to find information very quickly.  Let us write a small VBA Routine to see how this is used in programs.

Public Function PrimaryKey_Example1(ByVal EmpCode As Integer)
Dim db As Database, rst As Recordset

Set db = CurrentDb
Set rst = db.OpenRecordset("Employees", dbOpenTable)
rst.Index = "PrimaryKey" 'activate the Index on Employee Code

rst.Seek "=", EmpCode 'we are looking for the record of Employee Code provided
'Let us test whether the search for Employee Code was successfull or not
If Not rst.NoMatch Then
    MsgBox "EC: " & rst![ID] & " - " & rst![First Name] & " " & rst![last name]
Else
    MsgBox "EC: " & EmpCode & " Not found!"
End If

Set rst = Nothing
Set db = Nothing

End Function

The statement rst.Index = "PrimaryKey" activates the Index with the name PrimaryKey. Under PrimaryKey Index there can be more than one Field. One Table can have several Indexes in the Indexes Group with different combination of fields as well. If one field alone cannot maintain uniqueness of information then we can add other related fields under the required Index Group. We can activate the required Index depending on which way we would like to get the data organized before proceeding with processing steps.

It is not necessary that the field contents should be always numbers only instead it can be any value like FirstName or LastName fields or both or any combination of field types like text, date, number etc. except Memo field.  You can give any suitable name for the Index in the Index Name column.

The Recordset's Seek() method is used for search operations on the Table.  One of the Indexes should be active before the Seek() operation can be executed. 

In the above example the rst.Seek "=", Empcode statement checks for the Employee Code passed to the Index_Example1() function.  The statement look for the exact match ("=" ).

When the Index is defined with more than one field then search keys must be separated with commas in the Seek() method.  Let us modify the above program to provide multiple values for the Index Keys in the Seek() method, assuming that FirstName and LastName fields are the members of MyIndex.

Public Function PrimaryKey_Example2(ByVal strFirstName As String, ByVal strLastName As String)
Dim db As Database, rst As Recordset

Set db = CurrentDb
Set rst = db.OpenRecordset("Employees", dbOpenTable)
rst.Index = "MyIndex" 'activate the Index

'Search for the Employee record
rst.Seek "=", strFirstName, strLastName

'Let us test whether the search for the Employee was successfull or not
If Not rst.NoMatch Then
    MsgBox "Employee: " & rst![ID] & " - " & rst![First Name] & " " & rst![last name]
Else
    MsgBox "Employee: " & strFirstName & " " & strLastName & " Not found!"
End If

Set rst = Nothing
Set db = Nothing

End Function
Share:

Percentage on Report Summary

We have worked with a Query to solve this problem earlier in the Blog Post: Percentage on Total Query.  This time let us see how it is done on a Report.  Our task is to show detail-line-wise value’s percentage on Report Summary Total.

The solution is simple.  Create a Report with some values in it with Report level summary.  Add a Text Box in the detail section and write an expression to divide the Report Summary Value into the detail level value.

Let us try it out.

  1. Import the Order Detail Table from Microsoft Access Sample Database: C:\Program Files\Microsoft Office\Office11\Sample\Northwind.mdb
  2. Open a new Query in SQL View; without selecting a Table from the displayed list.
  3. Copy and Paste the following SQL String into the SQL editing window of the new Query:
    SELECT [Order Details].[Order ID], Sum([Order Details].Quantity) AS TQuantity, Sum([Order Details].[Unit Price]) AS UnitPrice, Sum([Unit Price]*[Quantity]) AS TotalPrice
    FROM [Order Details]
    GROUP BY [Order Details].[Order ID];
    
  4. Save the Query with the name OrderSummary.
  5. Design a Report (as shown in the image given below) with the Detail Section and Report Footer summary controls using OrderSummary as Source.
  6. Click on the Text Box at the Footer of the Report to select it.
  7. Display the Property Sheet (F4 or ALT+Enter) of the Text Box.
  8. Change the Name Property Value to GTPrice (stands for Grand Total Price).
  9. Write the expression =Sum([TotalPrice]) in the Control Source Property.
  10. Select the Text Box at the right end in the Detail Section and display its Property Sheet.
  11. Write the expression =[TotalPrice]/[GTPrice] in the Control Source Property.
  12. In the Format Property select the Percent format from the drop-down list.
  13. Type 2 in the Decimal Places Property.
  14. Save and Close the Report.
  15. Open the OrderSummary in Print Preview and check the detail line percentage value calculated on Report Footer Grand Total Price.

Want to know how to calculate and display Page-wise control totals; you can learn it from here?

Share:

Translate



PageRank
Your email address:

Delivered by FeedBurner

Search

Infolinks Text Ads


Blogs Directory

Popular Posts

Search This Blog

Blog Archive

Powered by Blogger.

Labels

Forms How Tos Functions MS-Access Security Reports msaccess forms Animations msaccess animation Utilities msaccess controls Access and Internet MS-Access Scurity MS-Access and Internet Queries External Links msaccess reports msaccess tips Menus and Toolbars Accesstips MsaccessLinks Process Controls Art Work Downloads msaccess How Tos Graph Charts msaccessQuery List Boxes Command Buttons Emails and Alerts Query Combo Boxes Custom Wizards DOS Commands ms-access functions msaccess functions msaccess graphs msaccess reporttricks msaccessprocess security advanced Access Security Array Custom Functions Data Macros Menus Property Report Top Values VBA msaccess email msaccess menus progressmeter Access2007 Auto-Number Command Button Copy Form Join Microsoft Numbering System Records Security Split SubForm Table Utility Variables Workgroup database msaccess wizards Access2003 Accounting Year Action Animation Attachment Binary Numbers Bookmarks Budgeting Calculation ChDir Color Palette Conditional Formatting Controls Data Filtering Data Type Defining Pages Diagram Disk Dynamic Lookup Error Handler Excel Export Expression External Field Type Fields Filter Form Instances Formatting Groups Hexadecimal Numbers Import Labels List Logo Macro Mail Merge Main Form Memo Methods Monitoring Object Reference Objects Octal Numbers Operating System Paste Primary-Key Product Rank Reading Recordset Rich Text Sequence SetFocus Summary Tab-Page Tables Time Difference Union Query User Users Water-Mark Word automatically commands function hyperlinks iSeries Date iif ms-access msaccess msaccess alerts pdf files reference restore switch text toolbar tutorial updating upload vba code

Featured Post

Function Parameter Array Passing

Last week we have explored the usage of ByVal (By Value) and ByRef (By Reference),  in the Function Parameter, to pass the value from  a Va...

Labels

Blog Archive

Recent Posts