Public Sub CreateIndexonView(strIndexName As String, strViewName As String, strFields As String)
Dim strSQL As String
strSQL = "Create Index " & strIndexName & " On " & strViewName & "(" & strFields & ")"
CurrentDb.Execute strSQL
End Sub
The information below is based on an article by Juan Soto at https://accessexperts.com/blog/2010/03/03/using-sql-server-views-with-access-index-needed-for-editing-data-2/
SQL Server views are one of the best tools a Microsoft Access programmer can use to limit exposure to data and improve Access performance.
Example usage:
CreateIndexonView “IDX_OrderID”, “vw_CustomerExpiredOrders”, “OrderID”