Microsoft Access
Overview
This skill helps AI agents work with Microsoft Access databases — designing tables, writing queries, building forms and reports, automating with VBA, and planning migrations to modern platforms. Access is widely used in small businesses and departments for data management, and agents should know how to build, maintain, and eventually migrate these systems.
Instructions
Step 1: Database Design
Table: Customers
CustomerID AutoNumber (Primary Key)
FirstName Short Text (50)
LastName Short Text (50)
Email Short Text (100), Indexed (No Duplicates)
Phone Short Text (20)
Company Short Text (100)
CreatedDate Date/Time, Default: =Now()
IsActive Yes/No, Default: Yes
Table: Orders
OrderID AutoNumber (Primary Key)
CustomerID Long Integer (Foreign Key -> Customers)
OrderDate Date/Time, Default: =Date()
TotalAmount Currency
Status Short Text (20), Validation: In ("Pending","Shipped","Delivered","Cancelled")
Table: OrderItems
ItemID AutoNumber (Primary Key)
OrderID Long Integer (Foreign Key -> Orders)
ProductID Long Integer (Foreign Key -> Products)
Quantity Integer, Validation: >0
UnitPrice Currency
Table: Products
ProductID AutoNumber (Primary Key)
ProductName Short Text (100)
Category Short Text (50)
UnitPrice Currency
UnitsInStock Integer, Default: 0
ReorderLevel Integer, Default: 10
Relationships (enforce referential integrity, cascade update, no cascade delete):
Customers (1) --- (many) Orders
Orders (1) --- (many) OrderItems
Products (1) --- (many) OrderItems
Design rules: AutoNumber PKs, proper data types with length limits, validation rules at table level, default values, indexes on frequently queried fields.
Step 2: Queries
-- Join with aggregation: total sales per customer
SELECT c.CustomerID, c.FirstName & " " & c.LastName AS FullName,
Count(o.OrderID) AS OrderCount, Sum(o.TotalAmount) AS TotalSpent
FROM Customers c INNER JOIN Orders o ON c.CustomerID = o.CustomerID
GROUP BY c.CustomerID, c.FirstName & " " & c.LastName
HAVING Sum(o.TotalAmount) > 1000
ORDER BY TotalSpent DESC;
-- Crosstab: monthly sales by category
TRANSFORM Sum(oi.Quantity * oi.UnitPrice) AS Revenue
SELECT p.Category
FROM Products p INNER JOIN OrderItems oi ON p.ProductID = oi.ProductID
INNER JOIN Orders o ON oi.OrderID = o.OrderID
WHERE o.OrderDate Between #2026-01-01# And #2026-12-31#
GROUP BY p.Category
PIVOT Format(o.OrderDate, "yyyy-mm");
-- Inactive customers (no orders in 90 days)
SELECT c.CustomerID, c.FirstName, c.LastName, c.Email
FROM Customers c
WHERE c.CustomerID NOT IN (
SELECT DISTINCT o.CustomerID FROM Orders o WHERE o.OrderDate >= DateAdd("d", -90, Date())
) AND c.IsActive = True;
-- Action: mark overdue orders
UPDATE Orders SET Status = "Overdue"
WHERE Status = "Pending" AND OrderDate < DateAdd("d", -30, Date());
-- Parameter query
SELECT o.OrderID, c.LastName, o.OrderDate, o.TotalAmount
FROM Orders o INNER JOIN Customers c ON o.CustomerID = c.CustomerID
WHERE o.OrderDate Between [Enter Start Date:] And [Enter End Date:];
Step 3: Forms & VBA
' Search form with dynamic filtering
Private Sub btnSearch_Click()
Dim strFilter As String
If Not IsNull(Me.txtSearchName) Then
strFilter = "LastName Like '*" & Me.txtSearchName & "*'"
End If
If Not IsNull(Me.cboStatus) Then
If Len(strFilter) > 0 Then strFilter = strFilter & " AND "
strFilter = strFilter & "Status = '" & Me.cboStatus & "'"
End If
Me.subResults.Form.Filter = strFilter
Me.subResults.Form.FilterOn = (Len(strFilter) > 0)
End Sub
' Validation before save
Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.txtEmail) Or Not Me.txtEmail Like "*@*.*" Then
MsgBox "Please enter a valid email address.", vbExclamation
Me.txtEmail.SetFocus
Cancel = True
End If
End Sub
Step 4: Reports & Export
' Export report to PDF
Private Sub btnExportPDF_Click()
DoCmd.OutputTo acOutputReport, "rptMonthlySales", acFormatPDF, _
"C:\Reports\SalesReport_" & Format(Date, "yyyy-mm-dd") & ".pdf"
End Sub
' Export query results to Excel
Public Sub ExportToExcel()
Dim xlApp As Object, xlWb As Object, rs As DAO.Recordset
Set xlApp = CreateObject("Excel.Application")
Set xlWb = xlApp.Workbooks.Add
Set rs = CurrentDb.OpenRecordset("qryMonthlySales")
Dim i As Integer
For i = 0 To rs.Fields.Count - 1
xlWb.Sheets(1).Cells(1, i + 1).Value = rs.Fields(i).Name
Next i
xlWb.Sheets(1).Range("A2").CopyFromRecordset rs
xlWb.Sheets(1).Columns.AutoFit
xlWb.SaveAs "C:\Reports\MonthlySales_" & Format(Date, "yyyy-mm") & ".xlsx"
xlWb.Close: xlApp.Quit
End Sub
Step 5: Automation
' Import CSV and deduplicate against existing data
Public Sub ImportCSV()
DoCmd.TransferText acImportDelim, , "ImportedData", "C:\Data\import.csv", True
CurrentDb.Execute "INSERT INTO Customers (FirstName, LastName, Email) " & _
"SELECT Trim(FirstName), Trim(LastName), LCase(Trim(Email)) " & _
"FROM ImportedData WHERE Email NOT IN (SELECT Email FROM Customers)"
CurrentDb.Execute "DROP TABLE ImportedData"
End Sub
' Link to SQL Server
Public Sub LinkSQLServerTables()
Dim tdf As DAO.TableDef, connStr As String
connStr = "ODBC;DRIVER={ODBC Driver 17 for SQL Server};SERVER=myserver.database.windows.net;DATABASE=MyDB;UID=admin;PWD=password;"
Set tdf = CurrentDb.CreateTableDef("dbo_Customers")
tdf.Connect = connStr
tdf.SourceTableName = "dbo.Customers"
CurrentDb.TableDefs.Append tdf
End Sub
Step 6: Migration Strategy
| Current |
Target |
Best For |
| Access tables |
SQL Server / Azure SQL |
Data > 2GB, multi-user |
| Access forms |
Power Apps |
Low-code, mobile access |
| Access reports |
Power BI |
Advanced analytics |
| Access + VBA |
Web app (Node/Python) |
Internet access, APIs |
| Everything |
Dataverse + Power Platform |
Full MS ecosystem |
Examples
Example 1: Build an order management database
User prompt: "Create an Access database for tracking customer orders with products, order items, and a search form to find orders by customer name or date range."
The agent will:
- Create four tables (Customers, Orders, OrderItems, Products) with AutoNumber primary keys, proper data types, and validation rules
- Set up relationships with referential integrity: Customers 1-to-many Orders, Orders 1-to-many OrderItems, Products 1-to-many OrderItems
- Build a search form with text box for customer name, combo box for status, and date range fields
- Add VBA
btnSearch_Click handler that constructs a dynamic filter string and applies it to a subform displaying matching orders
Example 2: Generate a monthly sales report and export to PDF
User prompt: "Create an Access report showing monthly sales totals grouped by product category, with subtotals per category and a grand total, then export it as a PDF."
The agent will:
- Write a crosstab query using
TRANSFORM Sum(Quantity * UnitPrice) pivoted by Format(OrderDate, "yyyy-mm") and grouped by product category
- Design a report with Group Header/Footer on Category (showing subtotals), Detail section for monthly figures, and Report Footer for grand total
- Add conditional formatting in the
GroupFooter_Format event to highlight categories with sales under $1,000 in red
- Implement a
btnExportPDF_Click handler using DoCmd.OutputTo to save the report as a dated PDF file
Guidelines
- Always compact and repair regularly — Access databases bloat over time
- Set the 2GB file size limit warning early — migrate before hitting it
- Split database: front-end (forms/queries) on user's machine, back-end (tables) on network share
- Back up .accdb files daily — no built-in replication or point-in-time recovery
- Use parameterized queries, not string concatenation — SQL injection applies to Access too
- Linked tables to SQL Server for multi-user scenarios (>5 concurrent users)
- Keep VBA in modules, not behind individual forms — easier to maintain and debug
- Error handling in every VBA procedure —
On Error GoTo ErrHandler
- Document table relationships, validation rules, and VBA in a design document
- Plan migration early — Access is a prototyping tool, not an enterprise platform
1---2name: ms-access3description: >-4 Build and manage Microsoft Access databases, queries, forms, reports, and VBA5 automation. Use when someone asks to "create Access database", "write Access6 queries", "build Access forms", "Access VBA macro", "migrate from Access",7 "Access report", "link Access to SQL Server", or "convert Access to web app".8 Covers table design, relationships, SQL queries, forms, reports, VBA9 automation, and migration strategies to modern platforms.10license: Apache-2.011compatibility: 'Microsoft Access 2016+, Microsoft 365 Access. Windows only.'12metadata:13 source: https://skillmd.com/skills/eliferjunior/ms-access14 author: terminal-skills15 version: 1.0.016 category: development17 tags:18 - microsoft-access19 - database20 - vba21 - forms22 - reports23---2425# Microsoft Access2627## Overview2829This skill helps AI agents work with Microsoft Access databases — designing tables, writing queries, building forms and reports, automating with VBA, and planning migrations to modern platforms. Access is widely used in small businesses and departments for data management, and agents should know how to build, maintain, and eventually migrate these systems.3031## Instructions3233### Step 1: Database Design3435```36Table: Customers37 CustomerID AutoNumber (Primary Key)38 FirstName Short Text (50)39 LastName Short Text (50)40 Email Short Text (100), Indexed (No Duplicates)41 Phone Short Text (20)42 Company Short Text (100)43 CreatedDate Date/Time, Default: =Now()44 IsActive Yes/No, Default: Yes4546Table: Orders47 OrderID AutoNumber (Primary Key)48 CustomerID Long Integer (Foreign Key -> Customers)49 OrderDate Date/Time, Default: =Date()50 TotalAmount Currency51 Status Short Text (20), Validation: In ("Pending","Shipped","Delivered","Cancelled")5253Table: OrderItems54 ItemID AutoNumber (Primary Key)55 OrderID Long Integer (Foreign Key -> Orders)56 ProductID Long Integer (Foreign Key -> Products)57 Quantity Integer, Validation: >058 UnitPrice Currency5960Table: Products61 ProductID AutoNumber (Primary Key)62 ProductName Short Text (100)63 Category Short Text (50)64 UnitPrice Currency65 UnitsInStock Integer, Default: 066 ReorderLevel Integer, Default: 106768Relationships (enforce referential integrity, cascade update, no cascade delete):69 Customers (1) --- (many) Orders70 Orders (1) --- (many) OrderItems71 Products (1) --- (many) OrderItems72```7374Design rules: AutoNumber PKs, proper data types with length limits, validation rules at table level, default values, indexes on frequently queried fields.7576### Step 2: Queries7778```sql79-- Join with aggregation: total sales per customer80SELECT c.CustomerID, c.FirstName & " " & c.LastName AS FullName,81 Count(o.OrderID) AS OrderCount, Sum(o.TotalAmount) AS TotalSpent82FROM Customers c INNER JOIN Orders o ON c.CustomerID = o.CustomerID83GROUP BY c.CustomerID, c.FirstName & " " & c.LastName84HAVING Sum(o.TotalAmount) > 100085ORDER BY TotalSpent DESC;8687-- Crosstab: monthly sales by category88TRANSFORM Sum(oi.Quantity * oi.UnitPrice) AS Revenue89SELECT p.Category90FROM Products p INNER JOIN OrderItems oi ON p.ProductID = oi.ProductID91INNER JOIN Orders o ON oi.OrderID = o.OrderID92WHERE o.OrderDate Between #2026-01-01# And #2026-12-31#93GROUP BY p.Category94PIVOT Format(o.OrderDate, "yyyy-mm");9596-- Inactive customers (no orders in 90 days)97SELECT c.CustomerID, c.FirstName, c.LastName, c.Email98FROM Customers c99WHERE c.CustomerID NOT IN (100 SELECT DISTINCT o.CustomerID FROM Orders o WHERE o.OrderDate >= DateAdd("d", -90, Date())101) AND c.IsActive = True;102103-- Action: mark overdue orders104UPDATE Orders SET Status = "Overdue"105WHERE Status = "Pending" AND OrderDate < DateAdd("d", -30, Date());106107-- Parameter query108SELECT o.OrderID, c.LastName, o.OrderDate, o.TotalAmount109FROM Orders o INNER JOIN Customers c ON o.CustomerID = c.CustomerID110WHERE o.OrderDate Between [Enter Start Date:] And [Enter End Date:];111```112113### Step 3: Forms & VBA114115```vba116' Search form with dynamic filtering117Private Sub btnSearch_Click()118 Dim strFilter As String119 If Not IsNull(Me.txtSearchName) Then120 strFilter = "LastName Like '*" & Me.txtSearchName & "*'"121 End If122 If Not IsNull(Me.cboStatus) Then123 If Len(strFilter) > 0 Then strFilter = strFilter & " AND "124 strFilter = strFilter & "Status = '" & Me.cboStatus & "'"125 End If126 Me.subResults.Form.Filter = strFilter127 Me.subResults.Form.FilterOn = (Len(strFilter) > 0)128End Sub129130' Validation before save131Private Sub Form_BeforeUpdate(Cancel As Integer)132 If IsNull(Me.txtEmail) Or Not Me.txtEmail Like "*@*.*" Then133 MsgBox "Please enter a valid email address.", vbExclamation134 Me.txtEmail.SetFocus135 Cancel = True136 End If137End Sub138```139140### Step 4: Reports & Export141142```vba143' Export report to PDF144Private Sub btnExportPDF_Click()145 DoCmd.OutputTo acOutputReport, "rptMonthlySales", acFormatPDF, _146 "C:\Reports\SalesReport_" & Format(Date, "yyyy-mm-dd") & ".pdf"147End Sub148149' Export query results to Excel150Public Sub ExportToExcel()151 Dim xlApp As Object, xlWb As Object, rs As DAO.Recordset152 Set xlApp = CreateObject("Excel.Application")153 Set xlWb = xlApp.Workbooks.Add154 Set rs = CurrentDb.OpenRecordset("qryMonthlySales")155 Dim i As Integer156 For i = 0 To rs.Fields.Count - 1157 xlWb.Sheets(1).Cells(1, i + 1).Value = rs.Fields(i).Name158 Next i159 xlWb.Sheets(1).Range("A2").CopyFromRecordset rs160 xlWb.Sheets(1).Columns.AutoFit161 xlWb.SaveAs "C:\Reports\MonthlySales_" & Format(Date, "yyyy-mm") & ".xlsx"162 xlWb.Close: xlApp.Quit163End Sub164```165166### Step 5: Automation167168```vba169' Import CSV and deduplicate against existing data170Public Sub ImportCSV()171 DoCmd.TransferText acImportDelim, , "ImportedData", "C:\Data\import.csv", True172 CurrentDb.Execute "INSERT INTO Customers (FirstName, LastName, Email) " & _173 "SELECT Trim(FirstName), Trim(LastName), LCase(Trim(Email)) " & _174 "FROM ImportedData WHERE Email NOT IN (SELECT Email FROM Customers)"175 CurrentDb.Execute "DROP TABLE ImportedData"176End Sub177178' Link to SQL Server179Public Sub LinkSQLServerTables()180 Dim tdf As DAO.TableDef, connStr As String181 connStr = "ODBC;DRIVER={ODBC Driver 17 for SQL Server};SERVER=myserver.database.windows.net;DATABASE=MyDB;UID=admin;PWD=password;"182 Set tdf = CurrentDb.CreateTableDef("dbo_Customers")183 tdf.Connect = connStr184 tdf.SourceTableName = "dbo.Customers"185 CurrentDb.TableDefs.Append tdf186End Sub187```188189### Step 6: Migration Strategy190191| Current | Target | Best For |192|---------|--------|----------|193| Access tables | SQL Server / Azure SQL | Data > 2GB, multi-user |194| Access forms | Power Apps | Low-code, mobile access |195| Access reports | Power BI | Advanced analytics |196| Access + VBA | Web app (Node/Python) | Internet access, APIs |197| Everything | Dataverse + Power Platform | Full MS ecosystem |198199## Examples200201### Example 1: Build an order management database202**User prompt:** "Create an Access database for tracking customer orders with products, order items, and a search form to find orders by customer name or date range."203204The agent will:2051. Create four tables (Customers, Orders, OrderItems, Products) with AutoNumber primary keys, proper data types, and validation rules2062. Set up relationships with referential integrity: Customers 1-to-many Orders, Orders 1-to-many OrderItems, Products 1-to-many OrderItems2073. Build a search form with text box for customer name, combo box for status, and date range fields2084. Add VBA `btnSearch_Click` handler that constructs a dynamic filter string and applies it to a subform displaying matching orders209210### Example 2: Generate a monthly sales report and export to PDF211**User prompt:** "Create an Access report showing monthly sales totals grouped by product category, with subtotals per category and a grand total, then export it as a PDF."212213The agent will:2141. Write a crosstab query using `TRANSFORM Sum(Quantity * UnitPrice)` pivoted by `Format(OrderDate, "yyyy-mm")` and grouped by product category2152. Design a report with Group Header/Footer on Category (showing subtotals), Detail section for monthly figures, and Report Footer for grand total2163. Add conditional formatting in the `GroupFooter_Format` event to highlight categories with sales under $1,000 in red2174. Implement a `btnExportPDF_Click` handler using `DoCmd.OutputTo` to save the report as a dated PDF file218219## Guidelines220221- Always compact and repair regularly — Access databases bloat over time222- Set the 2GB file size limit warning early — migrate before hitting it223- Split database: front-end (forms/queries) on user's machine, back-end (tables) on network share224- Back up .accdb files daily — no built-in replication or point-in-time recovery225- Use parameterized queries, not string concatenation — SQL injection applies to Access too226- Linked tables to SQL Server for multi-user scenarios (>5 concurrent users)227- Keep VBA in modules, not behind individual forms — easier to maintain and debug228- Error handling in every VBA procedure — `On Error GoTo ErrHandler`229- Document table relationships, validation rules, and VBA in a design document230- Plan migration early — Access is a prototyping tool, not an enterprise platform