Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2006
    Posts
    25

    Unanswered: getDatabaseName() function

    I've used a function called getDatabaseName() but it gives me a list of tables from an external database requires us to input the name of the table as it is spelled. Is there another function that anybody knows that will allow you to select the table as opposed to typing it completely?

    Access 2002

  2. #2
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    I'm confused. Are you trying to return a listing of the tables in a database (in an mdb file) or the database (mdb) name itself and it's location?
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  3. #3
    Join Date
    Jun 2006
    Posts
    25
    Sorry for the confusion. Let's say I have DB1 and DB2. From DB1 I am trying to import a table from DB2 using this module code. The current getDatabaseName is requiring me to type in the full name of the table from DB2 in order to import it. After I type it, it says confirms the table name, and if it's spelled correctly, it will import the table. Here is a portion of the code to give you an idea of what it does.

    Code:
    Public Function getTableName(db As Database) As String
    Tables = ""
    For Each t In db.TableDefs
    If Left(t.Name, 4) <> "MSys" Then
    Tables = Tables & t.Name & vbCr
    End If
    Next
    If Len(Tables) = 0 Then
    n = MsgBox("No user-defined tables found. Macro will exit.", vbOKOnly, "Error")
    End
    End If
    validSelection = False
    While Not validSelection
    s = InputBox("Database" & vbCr & vbCr & db.Name & vbCr & vbCr & _
    "contains the following tables: " _
    & vbCr & vbCr & Tables, "PLEASE ENTER TABLE NAME")
    checkForCancel (s)
    For Each t In db.TableDefs
    If t.Name = s Then
    validSelection = True
    getTableName = s
    End If
    Next
    If Not validSelection Then
    If MsgBox("Table " & s & " not found. Please re-enter table name.", _
    vbOKCancel, "Error") = vbCancel Then
    promptForExit
    End If
    End If
    Wend
    End Function
    Is there some other code that allows me to select a table from a list instead of typing in the name? Or an easier and less time consuming solution that can help?

  4. #4
    Join Date
    Aug 2006
    Posts
    559
    Quote Originally Posted by cervantes008
    Sorry for the confusion. Let's say I have DB1 and DB2. From DB1 I am trying to import a table from DB2 using this module code. The current getDatabaseName is requiring me to type in the full name of the table from DB2 in order to import it. After I type it, it says confirms the table name, and if it's spelled correctly, it will import the table. Here is a portion of the code to give you an idea of what it does.

    Code:
    Public Function getTableName(db As Database) As String
    Tables = ""
    For Each t In db.TableDefs
    If Left(t.Name, 4) <> "MSys" Then
    Tables = Tables & t.Name & vbCr
    End If
    Next
    If Len(Tables) = 0 Then
    n = MsgBox("No user-defined tables found. Macro will exit.", vbOKOnly, "Error")
    End
    End If
    validSelection = False
    While Not validSelection
    s = InputBox("Database" & vbCr & vbCr & db.Name & vbCr & vbCr & _
    "contains the following tables: " _
    & vbCr & vbCr & Tables, "PLEASE ENTER TABLE NAME")
    checkForCancel (s)
    For Each t In db.TableDefs
    If t.Name = s Then
    validSelection = True
    getTableName = s
    End If
    Next
    If Not validSelection Then
    If MsgBox("Table " & s & " not found. Please re-enter table name.", _
    vbOKCancel, "Error") = vbCancel Then
    promptForExit
    End If
    End If
    Wend
    End Function
    Is there some other code that allows me to select a table from a list instead of typing in the name? Or an easier and less time consuming solution that can help?
    I wonder if you can use something like this to let the user select specific tables from a list?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •