Open Table Selected in ListBox

Taff

Registered User.
Local time
Today, 15:11
Joined
Feb 3, 2004
Messages
158
Hi all,

I have a form with a listbox which displays table names with the following as the rowsource:-

Code:
SELECT [msysobjects].[Name], * FROM msysobjects WHERE ((([msysobjects].[Name]) Like "Codes_LP*"));

I was wondering if it is possible to have a command button that opens the table that I have selected in my listbox?

Thanks for your help

Anthony
 
If your listbox is called lstTables, you can use some code in the listbox's double-click event or behind a command button like this:
DoCmd.OpenTable Me.lstTables

Make sure your listbox is single-select (the default).

Also, I think your listbox rowsource can be abbreviated to:
SELECT * FROM msysobjects WHERE ((([msysobjects].[Name]) Like "Codes_LP*"));
As you have it, you are pulling the [Name] field twice. Also, it's a good idea NOT to use VBA reserved words (like Name) as field names.
 

Users who are viewing this thread

Back
Top Bottom