Results 1 to 2 of 2

Thread: How can I get Table Name in Database by VB Coding?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 1999
    Location
    Thailand
    Posts
    20

    Post

    I would like to Create Table in the database .But I have to check that the database has this table yet. How can I know ? And After that How can I Create table in code?

  2. #2
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    Calgary Alberta
    Posts
    359

    Post

    This is how I do it, not necessarily the best way, but it works. It will check the current database for a table, if it exists then will set booTable to true. If it doesn't find anything then it will make a table of the structure defined in strTable. Let me know if you have a problem or if this doesn't work.

    Matthew
    [email protected]


    ------
    dim strtemp as string, dbsNew as database
    dim intCounter as integer, intI as integer
    dim strTable as string, booTable as boolean
    strtemp = "CSVTabletemp" 'table name
    booTable = false
    Set dbsNew = CurrentDb

    strTable = "CREATE TABLE CSVTabletemp " _
    & "(temp text (255), temp2 text (255), temp3 text (255), " _
    & "temp4 text (255), temp5 text (255), temp6 text (255), temp7 text (255), " _
    & "temp8 text (255), temp9 text (255), temp10 text(255), " _
    & "temp11 text (255), temp12 text (255), temp13 text (255), temp14 text (255));"

    intCounter = dbsNew.TableDefs.Count - 1
    'the next should loop through to make sure the table doesn't exist, if it does, delete it
    For intI = 0 To intCounter
    If dbsNew.TableDefs(intI).Name = strtemp Then
    booTable = true
    Exit For
    End If
    Next intI

    if booTable = false then
    dbsNew.Execute strTable 'creates the temp table
    end if

    -------

Posting Permissions

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



Click Here to Expand Forum to Full Width