Posted on 1999-06-23
Medium Priority
Last Modified: 2010-05-02
How can I fill a list box with all the tables of from a database .MDB file and then choose one table from the list and delete that table. I use DAO/VB6 no data control.

Thanks in advance
Question by:abidsml
1 Comment

Accepted Solution

jdunck earned 60 total points
ID: 1519304
Create a project w/ a reference to DAO.

Paste this file into notepad, and save it as Form1.frm.

Add the form to the project you just created.

Change the OpenDatabase argument to the path of your database.



Begin VB.Form Form1
   Caption         =   "Form1"
   ClientHeight    =   3195
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4680
   LinkTopic       =   "Form1"
   ScaleHeight     =   3195
   ScaleWidth      =   4680
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton cmdDelete
      Caption         =   "Command1"
      Height          =   615
      Left            =   600
      TabIndex        =   1
      Top             =   2160
      Width           =   1455
   Begin VB.ListBox List1
      Height          =   1035
      Left            =   840
      TabIndex        =   0
      Top             =   720
      Width           =   3255
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim mdbDatabase As DAO.Database

Private Sub cmdDelete_Click()
   Dim pstrSQL As String
   'remove it from db
   pstrSQL = "DROP TABLE " & List1.Text
   mdbDatabase.Execute pstrSQL
   'remove it from the list
   List1.RemoveItem List1.ListIndex
End Sub

Private Sub Form_Load()
  Dim ptdTable As DAO.TableDef
   Set mdbDatabase = OpenDatabase("C:\Audit\Database\audit.mdb")

  For Each ptdTable In mdbDatabase.TableDefs
    List1.AddItem ptdTable.Name

End Sub


Featured Post

7 new features that'll make your work life better

It’s our mission to create a product that solves the huge challenges you face at work every day. In case you missed it, here are 7 delightful things we've added recently to monday to make it even more awesome.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

597 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question