Microsoft Access VBA Tutorials, Class Modules, SQL Techniques, and AI Integration Guides.

Hyperlink Opens Objects from Another Database

Introduction.

Hyperlinks in Microsoft Access provide a convenient way to open internal or external objects without the need to write Macros or VBA code. The Hyperlink Address and Hyperlink SubAddress properties are available for Label controls, Command Buttons, and Image controls.

We have already explored a few examples of using hyperlinks, and links to those articles are provided at the end of this page for reference.

If you haven’t experimented with these properties yet, let’s walk through a demo to understand how both properties can be used effectively.

The Sample Trial Run.

  1. Create a new Blank Form.
  2. Insert a Label control on the Form.
  3. While the label control is still in the selected state, display its Property Sheet (F4).

    Note: Hyperlink Address and Hyperlink SubAddress Properties are used for different purposes.

    • Hyperlink Address: for opening external objects, like Word Documents, Excel Worksheets, .PDF files, etc.
    • Hyperlink SubAddress: for opening internal objects, like Forms, Reports, Tables, Queries, and Macros.

    Let us open a Report from your database using the Hyperlink SubAddress property setting.

  4. Find the Hyperlink SubAddress property and write the following text into it:
    Report <Your Report Name>

    Replace <Your Report Name> text with one of your own report names (without the < > brackets). The correct format for writing a value into this property is <Object Type>, i.e., Form, Report, Table, Query, or Macro, followed by a space, followed by the actual object name.

  5. Change the Caption Property value of the Label to Open Report.
  6. Save the Form, with the Label control's Hyperlink SubAddress value set with the above changes.
  7. Open the Form in normal view and click on the label control.

You will see how your report is open in Print Preview.

Opening an Excel or Word File.

Now, try opening an MS-Word Document using the other property, the Hyperlink Address setting.

  1. Open your Form and create a second Label control on it.

  2. Display the property sheet of the label control.

  3. Change the Caption property value to Open Word Doc.

  4. Set the Hyperlink Address property value with the full pathname of a Word Document on your computer, like C:\My Documents\Letter.doc 

  5. Save the Form with the changes.

  6. Open the Form in normal view and click on the second label to open the Document in MS Word.

Note: You can open Web pages by setting the Hyperlink Address property value to a web address, say https://www.msaccesstips.com

The HyperLink Base.

If your external files, which you plan to open in Access, are all in one location C:\My Documents\ then you don’t need to duplicate it in every control but to specify the Path (C:\My Documents\) at one place: Hyperlink Base and only needs to write the document name (like Letter.doc or any other file on that location) in the Hyperlink Address property.

Let us try that:

  1. Click on the Office Button at the top-left corner and highlight the Manage option to display Database options (Access 2007). In Access 2003 and earlier versions, you will find this option in Tools Menu.

  2. Select Database Properties.

  3. Select the Summary Tab.

  4. Type C:\My Documents\ in the Hyperlink Base control (see the image given above)  and click OK to save it.

  5. Open your Form and remove the C:\My Documents\ text typed in for an earlier example, leaving the Letter.doc file name intact.

  6. Save the Form and click on the label control to open the Word Document.

  7. You may try to open any other document you have in that location, with only the file name changed in the label.

Opening Objects from another Microsoft Access Database.

If you have followed me so far with the above sample exercises, then with a few changes, we can do it.

  1. First, remove the text from the Hyperlink Base control ('C:\My Documents\') and leave the control empty.

  2. Create another Label control on your Form.

  3. Change the Caption Property value to Ext. Database.

  4. Set the Hyperlink Address property value to your external database path, like C:\mdbs\myDatabase.accdb.

  5. Set the Hyperlink SubAddress property value to Report myReport. Change the report name to match yours.

  6. Save the Form with the change.

  7. Open the Form in normal view and click on the label control.

Your external database will open first and will show your report in print preview.

Note: If your database is secured, then it will prompt for User ID and Password. You may try opening other objects: Form, Query, Macro & Table.

Share:

Microsoft Access Tutorial Database

Introduction.

In Microsoft Access 2003 and earlier versions, the Northwind.mdb sample database was automatically installed along with the program. This database served as a valuable resource for beginners, providing a practical environment to explore and practice the features of Microsoft Access.

Users migrating from Microsoft Excel often face challenges when transitioning to Access. Many are accustomed to organizing data in worksheets and simple tables, but these lack the flexibility and power of a true database system. While Excel does provide basic database-like features—such as sorting, searching, and filtering—its capabilities are limited compared to Access. Exploring Excel’s Help documentation on database concepts can be a useful starting point for learning fundamental rules of database design and management. By applying these practices, users can structure their Excel data in ways that make it easier to link or import into Access in the future.

Starting with Microsoft Access 2007, however, the Northwind database was no longer installed by default. Instead, users can create it manually from the available sample templates. The Northwind template includes comprehensive examples and tutorial material, making it an excellent resource for learning and practicing database concepts in Access.

How to Create NorthWind.accdb database.

  1. Open Microsoft Access 2007

    On the New Database screen, you’ll see several database template categories listed on the left panel. By default, the Featuring category is selected. In the main window, the Blank Database template appears at the top, along with other templates designed for specific purposes.

  2. On the left panel, find the Sample Template category and select it.
  3. Click on the Northwind 2007 Template.

    The database will be saved in the active folder by default. You may change the folder by clicking on the folder icon to the right of the database file name.

  4. Click the Create Button to create the sample database in your preferred folder.

Always use the sample database as a reference point when working through issues related to table design, setting up relationships, creating queries, forms, reports, or macros. Try experimenting with trial-and-error practices on the specific task you want to accomplish, using whatever knowledge and ideas you already have. This hands-on approach gives you deeper insight into the design process and, in most cases, helps you arrive at solutions on your own.

If you still cannot resolve the issue, the experience gained through trial and error will make it much easier to explain your problem clearly and seek help from other sources.

Access Users Forums.

You can search this Website for topics that you are interested in, or post your queries and get help from experts in Microsoft Access Users' Forums on the Internet. Links to some of the popular Forum Websites are given below:

  1. http://www.access-programmers.co.uk/forums/
  2. http://www.accessforums.net/#access-forums
  3. http://www.mrexcel.com/forum/microsoft-access/
Share:

Designing About Form for MS-Access Project

Introduction

This is all about the Microsoft Access About Form.

Once your Microsoft Access application development process is complete, you may design a small form called the About Form for your project. The About Form typically displays your project’s logo, name, version number, copyright information, and any other details you wish to include.

Sample About Form image of Windows Live Writer Application is given below as an example:

Designing an Access About Form is straightforward. You will typically need:

  • Two Label controls to display the application name and the current version number.

  • A Textbox to show the copyright information.

  • An Image control (optional) to include your custom logo, giving your application a unique identity.

Designing a Simple Access About Form.

Let us design such a small About Form to know what it takes to create one with a simple Logo. Our sample About Form in design view is given below for reference.

I have designed a simple logo in MS Word, captured a screenshot of it, modified it in MS Paint, and saved it as a .bmp file.@@@

  1. Open your Microsoft Access Application.

  2. Create a new Blank Form.

  3. Set the Width Property value of the Form to 3.93"

  4. Click on the Detail Section of the Form to select it.

  5. Set the Height property value to 1.53".

  6. Insert an Access Image control from the Toolbox on the left side of the Form and select the Project Logo image from your computer. You may select the Picture Property of the Image control and click on the build (...) button to browse and select the logo image from your computer, if you wish to change the image later.

    The Image Properties.

  7. Change the Image property values as given below:

    • Picture Tiling: No

    • Size Mode: Zoom

    • Picture Alignment: Center

    • Picture type: Embedded

  8. Ms-Access Label & Text Controls.

  9. Insert a Label control to the right of the logo and top of the Form, and resize it to make it wide enough to write the Application name in bold letters.

  10. Write the name of your Project in the Caption property, change the font size big enough to your liking, make it bold, and align the text to the center.

  11. Create another Label control below the first one, with the same width as the first label, and write the Version number of your Project, make it bold, and align the text to the center.

  12. Insert a Textbox below the earlier labels, and change its width to be as wide as the top labels.

  13. Copy and paste the following expression into the Control Source property of the textbox. ="Copyright " & Chr$(169) & Year(Date()) & " All Rights Reserved".

  14. Change the following Property values of Text-Box as given below:

    • Border Style: Transparent

    • Text Align: Center

    • Enabled: No

    • Locked: Yes

    • Tab Stop: No


    MS-Access Command Button.

  15. Create a Command Button below the textbox and position it in the center horizontally.

  16. Make the following changes to the Command Button:

    • Change the Name property value to cmdOK.

    • Change the Caption property value to OK.

    • Click on the Event Tab of the property sheet.

    • Select the On Click property and select [Event Procedure] from the drop-down list.

    • Click on the Build (...) button to open the VBA Module with the empty procedure start and end lines.

    • Copy the middle line of the Code given below and paste the line in the middle of the start and end lines of the VBA procedure (Private Sub cmdOK_Click() . . . End Sub). Or copy all three lines and paste them, overwriting the existing lines in the VBA Module.

    • Private Sub cmdOK_Click()
      DoCmd.Close
      End Sub
      

      When the Access User clicks on the Command Button, the above Code will run and the About Form will be closed.

  17. Save the Form and rename it as About or frmAbout.

  18. Open the About Form in normal View and see how it looks on the Access Application Window.

    The Property Value Changes.

    As you can see, the Access About Form needs some changes to make its appearance like a real About Form. Let us do that to give it the final touches.

  19. Make the following changes in the Form's Property Values as shown below:

    • Caption: About <your Project name here>

    • Pop Up: Yes

    • Modal: Yes

    • Default View: Form View

    • Allow Form View: Yes

    • Auto Center: Yes

    • Auto Resize: Yes

    • Fit to Screen: No

    • Border Style: Dialog

    • Record Selectors: No

    • Navigation Buttons: No

    • Dividing Lines: No

    • Scroll Bars: Neither

    • Control Box: Yes

    • Close Button: No

    • Min Max Button: None

  20. Save the Form after the above changes.

    View The Application About Form in Normal View.

  21. Open the About form in Normal View.

    A sample Image of the completed About Form in normal view is given below.

You must add an Option in the Customized Menu of your Project to enable the User to open the Access Application About Form if he/she wish to do so. Alternatively, you may add a Command Button on the Main Form of your Project to do that.

Share:

Appending Data from Excel to Access

Introduction

Last week, we tried out an interesting method of writing a range of Excel data directly into a Microsoft Access Table. Each row of cells is transferred into the table as a single record. If you haven't come across that article, then you may find it here.

This is an equally interesting method.  The selected Worksheet contents are appended to the Access Table with its specified columns in the SQL.

A sample image of the Worksheet data is given below:


The VBA Code

Private Sub CommandButton1_Click()
On Error GoTo CommandButton1_Click_Error
'Create Database connection Object
Set cn = CreateObject("ADODB.Connection")
'Access Database must be in the same location of the Worksheet 
dbpath = Application.ActiveWorkbook.Path & "\Database4XL.accdb"
'Get Workbook Full Pathname
dbWb = Application.ActiveWorkbook.FullName
'Get Active worksheet name
dbWs = Application.ActiveSheet.Name
'Create Data Target Connection string to open a session for data transfer
scn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & dbpath
'Datasheet name to add at the end of the Workbook Name, to complete the
'FROM clause of the SQL String.
dsh = "[" & dbWs & "$]"
'Open session
cn.Open scn

'Append Query SQL String
ssql = "INSERT INTO Table1 ([Desc], [Qrtr1], [Qrtr2], [Qrtr3], [Qrtr4]) "
ssql = ssql & "SELECT * FROM [Excel 8.0;HDR=YES;DATABASE=" & dbWb & "]." & dsh

'Run SQL
cn.Execute ssql

MsgBox "Data Added to " & dbpath & " Successfully."

CommandButton1_Click_Exit:
Exit Sub

CommandButton1_Click_Error:
MsgBox Err & " : " & Err.Description, , "CommandButton1_Click()"
Resume CommandButton1_Click_Exit

End Sub

Courtesy:
The above VBA code was taken from a Forum Post on www.mrexcel.com/Forum and modified to run on the same sample data presented in the earlier article published last week.

The Code on the Worksheet VBA Module is run from the Command Button1 Click Event Procedure.

  1. Roundup Function of Excel in MS-Access
  2. Proper Function of Excel in Microsoft Access
  3. Appending Data from Excel to Access
  4. Writing Excel Data Directly into Access
  5. Printing MS-Access Report from Excel
  6. Copy-Paste Data From Excel to Access 2007
  7. Microsoft Excel-Power in MS-Access
  8. Rounding Function MROUND of Excel
  9. MS-Access Live Data in Excel
  10. Access Live Data in Excel- 2
  11. Opening an Excel Database Directly
  12. Create an Excel Word File from Access
Share:

Writing Excel Data directly into Access Table

Introduction.

Microsoft Access allows you to import data from external sources such as dBase, FoxPro, Excel, or even another Access database. Likewise, you can also export data from Access to these applications, making data exchange and integration seamless.

Following is a list of topics I have published earlier, either on importing, exporting, or working with external data sources from Microsoft Access:

Today, we will explore how to add a range of Excel cell data directly into an Access Table by running the VBA Code from within Excel.

The Algorithm of the program is as given below:

  1. Create an Access Application Object and open it.

  2. Open the target database within the Access Application.

  3. Keep the Access Application window hidden.

  4. Open the target table from the Database.

  5. Take the count of Rows from one of the Excel data columns.

  6. Open a repeating loop to write the Excel data one row at a time, from the second row onwards.

  7. Repeat the writing action till all the rows are transferred to the Access Table.

  8. Close the table and database, and quit the MS-Access Application.

The Excel VBA Code is run by clicking a Command Button on the Excel Sheet. A sample image of the Excel Sheet with data and a Command Button is given below:

The Target Table Structure image is given below:


The Excel VBA Code

Sub Button1_Click()
    Dim objAcc As Object
    Dim recSet As Object
    Dim DataRow As Long, EndRow As Long
    
    On Error GoTo Button1_Click_Err
    
    'Create Access Application Object
    Set objAcc = CreateObject("Access.Application")
    'Open Database in Microsoft Access window
    objAcc.OpenCurrentDatabase "F:\mdbs\Database4XL.accdb", True
    'Keep Access application window hidden
    objAcc.Visible = False
    
    'Open Access Table to add records from Excel
    Set recSet = objAcc.CurrentDb.OpenRecordset("Table1")
    'Take actual row counts of data for transfer
    EndRow = Sheet1.Range("A" & Rows.Count).End(xlUp).Row

    With recSet
      For DataRow = 2 To EndRow
        .AddNew
        ![Desc] = Sheet1.Range("A" & DataRow).Value
        ![Qrtr1] = Sheet1.Cells.Range("B" & DataRow).Value
        ![Qrtr2] = Sheet1.Cells.Range("C" & DataRow).Value
        ![Qrtr3] = Sheet1.Cells.Range("D" & DataRow).Value
        ![Qrtr4] = Sheet1.Cells.Range("E" & DataRow).Value
        .Update
      Next
    End With
    recSet.Close
    objAcc.Quit
    Set objAcc = Nothing

Button1_Click_Exit:
Exit Sub

Button1_Click_Err:
MsgBox Err & " : " & Err.Description, , "Button1_Click()"
Resume Button1_Click_Exit
    
End Sub
Courtesy:
The non-functional raw VBA Code presented by a User at www.mrexcel.com/forum/microsoft-access was modified by me to make it functional and was originally submitted there.

The first field of the table is an ID field with the data type AutoNumber. The ID field value is automatically generated when data is inserted into the other fields.

  1. Roundup Function of Excel in MS-Access
  2. Proper Function of Excel in Microsoft Access
  3. Appending Data from Excel to Access
  4. Writing Excel Data Directly into Access
  5. Printing MS-Access Report from Excel
  6. Copy-Paste Data From Excel to Access 2007
  7. Microsoft Excel Power in MS-Access
  8. Rounding Function MROUND of Excel
  9. MS-Access Live Data in Excel
  10. Access Live Data in Excel- 2
  11. Opening an Excel Database Directly
  12. Create an Excel Word File from Access

Share:

Legacy Custom Menus Toolbars in Access2007

Introduction.

Custom Menu of Access 2003 in Access 2007.

You may have invested considerable time designing custom menus and toolbars in your MDB database. However, after upgrading to Microsoft Access 2007 and opening your database with the new version, you might notice that the customized menus and toolbars have disappeared.

The Add-In Menu.

Your custom menus and toolbars are not lost—they are still available. In Microsoft Access 2007, they are stored under the Add-Ins tab. Simply click on the Add-Ins tab on the Ribbon, and you will find all your custom menus and toolbars there. Refer to the sample image below for guidance.

Have you noticed the group name Custom Toolbars appearing at the bottom of the Add-in Menu?

But the Access 2007 Menu Bars also appear at the top.  You want to turn off the default Access 2007 Menus and Toolbars from the top and replace them with your Custom Menus and Toolbars.


Access Option Changes.

Do the following to get that done:

  1. Click on the Office Button (Top left corner).
  2. Select Access Options.
  3. Select the Current Database.
  4. Move the scroll bar down to find the Ribbon and Toolbar Options as shown in the image given above.
  5. Select your Custom Menu Bar name from the drop-down list, replacing the text (Default).
  6. Select your Shortcut Menu Bar name from the drop-down list, replacing the text (Default).
  7. Remove the check marks from the next three options:
    • Allow Full Menus.
    • Allow Default Shortcut Menu.
    • Allow Built-in Toolbars.
  8. Click OK to save changes and come out of Access Options.

  9. One more step to go:

  10. Close the database and open it again to register the changes.

Now that the Menu Bars and Tool Bars are in complete control of your Application, they will look like the image given above.

You want to restore Access 2007 Menus and Toolbars, then open the MDB file by holding the Shift-Key, to prevent Auto-Macro from running and to get control of the database window.  Go through Steps 1 to 9 and reverse what you did earlier.

Share:

Sub-Report Summary Value in Main Report Calculations

Introduction.

How to bring the sub-report summary value to the main report and use it in calculations?

But first, we need a ready-made report for our project.

Download links for the sample database are provided below. Choose the version you need. The demo database is created in Microsoft Access 2007 format and is fully compatible with later versions as well.

First, take a look at the following images:

  1. Print Preview of the finished report.
  2. Original Report Preview. 
  3. Changes were made to the Report in Design View to get the result shown in the first image above.


    Download Links.

  4. Sample Database Download Links for Microsoft Access 2007 and 2003 Versions are given below.


  5. Download the suitable sample database.

    In short, our task is to add the sub-report category total to the Footer Section of the Sales by Category sub-report. Get the summary value of each category for the main report header.  Calculate the percentage of each category of product sales value on Grand-Total Sales Value (or Percentage = Category Sales Value / Total Sales value of all Categories * 100).  We can do this by adding a few text boxes to both reports and writing a few expressions in them.

    The Sub-Report Changes.

    Let us start with the Sales by Category, Sub-report first.

  1. Open the downloaded database.

  2. Open Sales by Category, Sub-report in design view.

  3. Right-click on the Report Footer bar and select Properties to display the Property Sheet.

  4. Select the Height Property and change the property value to 0.33” or 0.838 cm.

  5. Select the Text Tool from the Toolbar above and draw a text box on the Report Footer area below the Product Sale column.

  6. Write the expression =Sum([ProductSales]) in the Control Source property of the text box. Change the Name property value to SubTotal.

  7. Modify the Caption property value of the child label to read as Sub-Total.

  8. Save and close the Sales by Category Subreport.

    The Main-Report Changes.

  9. Open the Sales by Category main report in Design View.

  10. Create a Text Box, on the Header Section of the Report, to the right of the report heading.

  11. While the text box is in the selected state, display the property sheet (F4).

  12. Write the expression =Sum([ProductSales]) in the Control Source property. Change the Name property value to TotalSales. Change the Caption property value of the child label to Total Sales.

    Note: The above expression calculates the total product sales value across all categories on the main report. When used in the sub-report, however, the same expression calculates the sales value of the current product category (for example: Beverages). This gives us two values: the SubTotal for a specific category in the sub-report, and the TotalSales for all categories in the main report.

    With these values, we can calculate the percentage contribution of a particular category using the formula:

    Percentage=SubTotalTotalSales×100\text{Percentage} = \frac{\text{SubTotal}}{\text{TotalSales}} \times 100

    However, since SubTotal is calculated in the sub-report, it cannot be directly referenced in the parent (main) report. To use it in the main report—especially when there are multiple sub-reports—we must explicitly specify the location of the control or expression within the sub-report.

  13. Create a text box below the Category Header bar to the right of the Category Name heading, move the text box to the right, and position it under the Total Sales calculation control on the Report Header.

  14. Right-click on the Control Source Property of the text box and select the Build option from the displayed list to open the expression builder control.

    • Click on the = symbol to insert it into the expression editor window.

    • Double-click on the + symbol on the left side of the Reports option to expand and show other options.

    • Double-click on Loaded Reports.

    • Double-click on the Sales by Category main report to display the Sub-Report's name.

    • Click on Sales by Category Subreport to display its control names in the next column.

    • Find the Subtotal control in the list and double-click on it.

      The reference to the SubTotal control in the sub-report can be written as:

      [Sales by Category Subreport].[Report]![SubTotal]

      This reference can be inserted directly using the Expression Builder. Alternatively, if you already understand how to write the reference correctly, you can type it directly into the Control Source property without going through the Expression Builder.

      With practice and by studying Microsoft Access’s addressing conventions, you will quickly become comfortable writing these references manually for use in Reports or Forms.

    • Click OK to come back to the Control Source property of the text box with the reference of the subtotal control and to write the rest of the expression to calculate the percentage.

    • Type /[TotalSales] at the end of the subtotal reference. Have you noticed the slash on the left side of the expression snippet?

    • Select Percent from the drop-down list of the Format property. With these settings, we don’t have to write *100 part in the expression.

    • Change the Caption of the child label to Category %. Change the font size of the Text box and child label to 12 points and make Font-weight Bold.

    Report Sample Print Preview

    Our Report is almost finished, but we need a little more change, and that comes next after we preview the progress of our work so far

  15. Save the changes we have made in the Report and open it in Print Preview to see the result of the changes we have made to the report so far.

    The Report should look like the image below.

  16. Move the Report to the next page.

    The Total Sales value of the Report Header Section is not appearing on the second page.

    By default, the Report Header section prints only on the first page of the report, and the Report Footer section prints only on the last page. This means that any headings or calculations placed in the Report Header will not appear on subsequent pages.

    However, we often want the report heading and certain calculated values to appear on every page. Content placed in the Page Header section is repeated across all pages, making it the ideal place for such information.

    The challenge is that aggregate functions like SUM(), Count(), and similar expressions do not work in the Page Header section. For example, we cannot directly place a SUM() calculation there. But we do want the calculated value from the Total Sales control (defined in the Report Footer or another valid section) to appear consistently at the top of every page.

    To achieve this, we make the following adjustments:

    Move the report heading from the Report Header to the Page Header, so it prints on every page.

    Reference the Total Sales control (which performs the calculation in a valid section, such as the Report Footer) from within the Page Header. By pointing to the existing Total Sales control, its value can be displayed in the Page Header even though aggregate functions cannot be calculated there directly.

    With this approach, both the heading and the calculated Total Sales value will appear consistently on every page of the report.

    The Final Changes.

    • Open the report in design view.

    • Drag the Category Name header bar down to get enough space for the Page Header Section, to cut and paste the Report Heading there.

    • The highlight report heading and the report date controls (leave alone the Total Sales textbox), cut, and paste into the Page Header Section.

    • Select the Total Sales text box, copy and paste it into the Page Header Section, and move the position below the text control on the Report Header Section.

    • Write the expression = [TotalSales] (the Name of the total sales calculation text box on the header section) in the Control Source property (overwriting the existing expression) of the copied text box.

      This will display the value of the Header Section text box, where the Total Sales value is calculated.  

    • Select the Header Section text control along with the child label and set their Visible Property value to No, to keep it hidden when the report is previewed or printed.

    • Save the report with the changes.

      Print Preview the Report.

    • Open the Sales by Category report in Print Preview, move the pages forward, and check the headings and category percentage values.

  17. Next time you want to do something like this, you can do it in a few minutes.

Share:

Editing Hyperlink Address Manually

Introduction.

Hyperlinks are everywhere on the Internet, and Microsoft Access supports them, too. In Access, hyperlinks can be used to open objects—such as Tables, Forms, Reports, or Queries—with a simple click, without writing a single line of VBA code or creating a Macro. They can also be created in Tables or Forms to build menus that open various database objects. Beyond Access, hyperlinks can be used to launch external files such as Word documents, Excel worksheets, PDFs, text files, and more.

In Access, hyperlinks can be created or edited manually by entering their different segments in the correct order, either in a table field or on form controls. More commonly, editing is done through the Edit Hyperlink dialog box, which appears when you right-click on a hyperlink control. 4 Segments of Hyperlink-Address in MS-Access.

The Hyperlink address line is divided into four segments:

  1. Display Text: the text that appears in a field or control, indicating the hidden link's purpose
  2. Address: external file's path-name
  3. Sub-Address: Internal Object Name, to open Form, Report, etc.
  4. Screen-tip: the text displays as a tooltip.

Hyperlink syntax is as follows:

Display Text#Address#Sub-Address#Tool-tip text

The Hyperlink Data type field can store a maximum of 2048 characters.

You can find more details and usage of Hyperlinks in the earlier Post: Open Forms with Hyperlinks in Listbox.

Editing Hyperlink Manually.

Let us get into the manual editing of the Hyperlink topic:

We will create a sample table with a Hyperlink field to try out the manual editing exercise.

  1. Create a table with a single field and data type Hyperlink.
  2. Save the table with a name.
  3. Open the table in datasheet view.

    If you know how to enter Hyperlink data into the field manually, you may do so by following the hyperlink syntax shown below.

    Example: My Excel File#C:\\\My Documents\Workbook1.xls##Click

  4. After entering the sample hyperlink in the field, open the table in the datasheet view.

    You will see that the hyperlink field is active, and the only text showing is the Display Text (My Excel File) part of the hyperlink information.

  5. Move the mouse pointer over the field, and it changes the mouse pointer to a hyperlink pointer (a Hand with an index finger).

    If you click on the field to edit the hyperlink information, it will only open the document specified in the second segment.

    If you right-click on the field, the shortcut menu, which carries the hyperlink editing options in a dialog box, is displayed.  You may key in values at appropriate controls to change the hyperlink values.  You cannot type values directly into the hyperlink field.

    Simple Trick to Edit Hyperlink Manually.

    But we can manually edit the field with a simple trick.

  6. Close the Table for now.
    • Click on the Office Button.
    • Select Access Options.
    • Select Advanced.
    • Find the Behavior Entering Field options.
    • Select Go to end of the field option.
    • Click OK to close the Access Options control.
  7. Open the Table after completing the above steps.

You can see that the insertion point is positioned at the end of the field value, exposing the hyperlink information. Move the insertion point back to the location where you need to edit the field.

If you have more than one record to edit, then change them and reset the Behavior Entering Field option to Select Entire Field.

TIP:

If you would like to show the full Pathname of the File as display text, then copy the second segment hyperlink value and paste it into the display text position also.


Stand-alone Label Controls Have Hyperlink Properties.

The Label control on the Form can be used as a hyperlink control.  The label control has Hyperlink Address & Hyperlink Sub-Address properties; use the Caption property to set the Display Text value of the hyperlink. Set the Special Effect property value to Raised, to make it look like a Command Button.

Share:

Alphabetized Customer List

Introduction.

If you are new to Microsoft Access report design, this simple tutorial on creating an alphabetized customer list will give you a clear understanding of the basics. It provides valuable insight into the steps involved in designing a report. We will need the following steps to complete our task:

  1. Prepare the Customers' source data in a SELECT Query for the report.

  2. Open a new report in Design View.

  3. Insert the SELECT Query name into the Record Source Property of the Report.

  4. Use the Data Grouping and Sorting option of the Report to organize and display A, B, C, etc., in the Group Header.

  5. Design the Report.

  6. Preview the Report.

A Sample Report.

Sample alphabetized list of customers. Report Preview is given below:


Designing A Report.

Get Some Sample Data.

But, first, we need some ready-made sample data for our Report

Let us start by importing the Customers Table from the Northwind sample database.

  1. Click on the External Data Menu.

  2. Click on the Access Tool button to display the Import control dialog box, to specify the Source and destination of data.

  3. Click on the Browse... Button to locate the Northwind sample database, select the file, and click Open.

    The selected file pathname is inserted into the File Name control in the dialog box.

    The first option is already selected as the default to import one or more required Access Objects from the selected Access database.

  4. Click OK to open the selected Access Database and expose its Tables, Queries, Reports, etc.

  5. Click on the Tables tab, select the Customers table, and click OK to import the selected table.

    The next step is to create a SELECT Query using the Customers table as the Source.

  6. Click on the Create menu and select Query Design from the Other group.

  7. Click the Close button to close the Show Table dialog box, without selecting any object from the displayed list.

  8. You will find the SQL View option on the extreme left of the Toolbar and select it to display the Query's SQL editing window.

    You will find the SQL statement SELECT in the window.

  9. Copy the SELECT Query Code given below and paste it into the SQL window, overwriting the existing SELECT statement.

    SELECT Left([First Name],1) AS Alpha, [First Name] & " " & [Last Name] AS CName
    FROM Customers
    ORDER BY Left([First Name],1), [First Name] & " " & [Last Name];
    

    In the SQL string shown above, we are working with only two columns of data. The first column, named Alpha, contains a single character from each row—the leftmost character of the customer’s first name—extracted using Microsoft Access’s built-in string function Left(). Access also provides other useful string functions in this category, such as Right(), Mid(), and more.

    The second column, named CName, contains the customer’s full name, created by joining the first and last names together with a space in between. When building query expressions like this, it is always a good practice to assign simple and meaningful names to the calculated columns. This makes it much easier to remember and reference them later in reports or forms. If you don’t provide explicit names, Access will automatically assign generic names such as Expr1, Expr2, and so on, which can be confusing when working with queries.

    In the ORDER BY clause of the query, both columns are sorted in ascending (A-Z) Order, first on the Alpha column, and then on the CName column.

  10. Save the Query with the name Customer ListQ.

  11. Open the Customer ListQ in the datasheet view and check the data.

    A sample image of what we are going to create is given below for reference:

The Design Task.

Let us design the Report.

  1. Select Report Design from the Create menu.

    An empty Report is open in Design View, with its Property Sheet. The first priority is to define our Customer ListQ Query as the Record Source of our report. If the property sheet is not displayed, then click on the Property Sheet toolbar button to display it.

  2. Select the Data Tab on the Property Sheet.

  3. Click on the Record Source property and click on the drop-down list at the right end of the property.

  4. Find Customer ListQ Query (use the slider, if necessary) and select it from the drop-down list to insert it into the Record Source property.

  5. Click on the Group & Sort Toolbar button from the Group & Totals Group under Design Menu, if it is not already in the selected state, to display the Group and Sort controls under the Footer of the Report.

  6. Click on the Add a Group control displayed in the Group, Sort, and Total shown below the empty report.

  7. Click on the Alpha column name displayed in the Query columns list.

    You can see that the Alpha Group Header is now appearing between the Page Header and Detail Sections of the empty report.

    We must sort the customer names appearing under a particular character group (say A, B, C group) so that they will appear in proper order as well. 

    Note: We have sorted the data in the Query by defining the ORDER BY clause, but we must define Grouping and Sorting on the Report as well to make them appear in proper order on the Report as well.

  8. Click on Add a Sort control and select CName from the list.

    Now, let us create the Heading of the Report, Group headings (A, B, C, and so on), and a customer names list to appear under each group.

  9. Click on the Label control to select it, and draw a rectangle wide enough to write the heading text "CUSTOMER LIST", select Bold and Italic formatting styles, and change the font size to 16.

  10. Select the TextBox control and draw a text box on the Alpha Header Section of the report.

  11. Click on the Data Tab on the Property Sheet and select Alpha from the Control Source drop-down list. Change the font style to Bold and character size to 16.

  12. Select the child label of the text box and delete it.

  13. Create another text box in the Detail Section of the Report, below the Alpha Header control.

  14. Select the CName column name from the drop-down list in the Control Source property under the Data Tab on the property sheet of the text control.

  15. Reduce the Detail Section height by dragging the Page-Footer section bar up to touch the text box's edge.

  16. Save the report with the name: Customer List.

    Print Preview the Report.

  17. Open the Customer List report in Print Preview to view.

If the Heading, Group heading, and customer list are not properly aligned to the left in your report, as shown in the first image at the top, try to align all the controls to the left.

Share:

Archiving Master Data

Introduction.

Over time, the Master Table in a database can grow substantially, containing thousands—or even millions—of records. Since the maximum logical size of a Microsoft Access database is only 2 GB, routine repairing and Compacting may not be enough to maintain optimal performance. As the table grows, the processing time for queries and report generation will continue to increase.

Most of the older records in the master table are not required for daily or monthly reporting and querying. However, they may still be needed for year-end processes, historical analysis, or setting business targets for the upcoming year.

Typically, older records are marked with an archived flag and retained in the master table, while active records are filtered for routine reports and queries to monitor ongoing business activities. As the table size increases, this filtering and sorting process can become slower, impacting overall database performance.

Maintaining Data of the Earlier Period.

Removing old data from the main table and storing it in a separate database will significantly improve the performance of the active database. The archived data, stored in a database such as Archive.accdb, can still be accessed whenever needed for year-end processes or historical analysis.

There is no need to permanently link the archived tables to the front-end database. Instead, you can directly reference the archived tables in a UNION query, combining them with the active master table only when required. This combined dataset can then serve as the source for year-end processing. (More details on creating UNION queries can be found [here].)

Before we get to that, let us first see how to safely transfer old records from the master table (tblMaster) into the archive database (Archive.accdb). For this example, we will assume that the database is configured in a Front-End/Back-End setup.

The Prelude of our Action Plan.

We need the following steps to complete the process:

  1. Create a new Access Database: Archive in location C:\mdbs or in a location of your preference.

    Note: If you are working on a shared network server, create (or use an existing) folder where you have the necessary access rights and save the Archive.accdb there. Databases stored on the server are usually included in the administrators’ daily backup routine, ensuring that your archive remains safe and can be recovered if needed. For more details, see: [Database Daily Backup].

  2. Close archive.accdb database.

  3. Open the Back-End Database.

  4. Transfer only the Structure of tblMaster into the Archive.accdb

  5. Create a SELECT Query on tblMaster with an appropriate criterion to select the old data.

  6. Open the Select Query in Datasheet View, take the total record count, and note it down.

  7. Change the SELECT query into an Append Query.

  8. Save and run the Append Query to transfer the selected data directly to the archive.accdb database into the table tblMaster.

  9. Close the BE database and open the Archive database.

  10. Open tblMaster in the archive database and check the count of records that matches the count taken earlier. If not, investigate the cause and redo from step 5 onwards, after deleting the wrong data in the tblMaster of the Archive.

  11. Close the Archive and open the BE database.

  12. Create a Delete Query that uses tblMaster with the same criteria you have used in the Append Query.

  13. Open the Delete Query in Datasheet View and take the count of records, and ensure that it matches the count you have taken earlier.

  14. Run the Delete Query to remove the records from the tblMaster table from the BE database.

  15. Run the Repair and Compact option to reduce the database size.

  16. Close the BE database and open the FE database.

    Linking Old Data to Front-End (FE) Database.

  17. Create a Union Query to combine data from tblMaster in BE and from tblMaster in Archive.

Let us execute the above-defined Plan.

Steps 1 to 3 are self-explanatory.

In step 4: Right-click on tblMaster to display a shortcut menu.

  • Highlight the Export option and select Access Database from the displayed menu.

  • Click on the Browse button and select the archive.accdb database and click Save to come back to the Export dialog box.

  • Click OK to open up the Export Options dialog box.

  • Select the Definition Only option to transfer the tblMaster Table Structure into the Archive.

Step-5: Select Query Code:

SELECT tblMaster.*
FROM tblMaster
WHERE (((tblMaster.mstDate)<Dateserial(1981,1,1)));

The above criteria will select all the records of 1980 and the earlier period.

Step 6 is self-explanatory.

Step 7: Open the Query created in step 5 in the design view.

  • Click on the Append Query button on the Toolbar.

  • Select tblMaster from the Table Name drop-down control in the dialog box.

  • Select Another Database Radio Button.

  • Click on Browse… Command Button to find the archive.accdb database, select it and click OK to come back to the dialog box in Query Design View.

  • Click OK on the dialog box to change the Select Query to an Append Query. The Sample append query SQL is given below for reference.

    INSERT INTO tblMaster IN 'C:\mdbs\archive.accdb'
    SELECT tblMaster.*
    FROM tblMaster
    WHERE (((tblMaster.mstDate)<DateSerial(1981,1,1)));
    
  • Open the Append Query in Datasheet View and check the record count with the count you took earlier.

  • If both counts match, then save the Append Query.

Step-8: Right-click on the Append Query and select Open to Run the Query to extract selected data from the tblMaster table and to append it to the archive.accdb tblMaster table.

  • Click the Yes Command Button on the warning message control to reconfirm the action.

Step-9 to Step-11: Self-explanatory.

Step-12:  Sample Delete Query SQL is given below:

DELETE tblMaster.*, tblMaster.mstDate
FROM tblMaster
WHERE (((tblMaster.mstDate)<DateSerial(1981,1,1)));

Step-13 to Step-16: Self-explanatory.

Step-17: Sample Union Query SQL is given below:

SELECT tblMaster.* 
FROM tblMaster
UNION ALL SELECT tblMaster.*
FROM tblMaster in 'C:\mdbs\archive.accdb';

Save the Union Query with the name tblMasterQ. Use tblMasterQ as Source Data for all year-end processes or wherever you need all the data together.  For other purposes, your database will run faster.

You can continue to transfer data when they become old, into the Archive, and delete them from the BE database.  No other change is required anywhere.

Technorati Tags:
Share:

PRESENTATION: ACCESS USER GROUPS (EUROPE)

Translate

PageRank

Post Feed


Search

Popular Posts

Blog Archive

Powered by Blogger.

Labels

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