+ Reply to Thread
Results 1 to 3 of 3

Using a Variable in vba SQL to create a table

  1. #1
    Registered User
    Join Date
    07-25-2008
    Location
    England
    Posts
    8

    Using a Variable in vba SQL to create a table

    Hi, Im trying to create a database in Access from Excel. It creates a Database called SOA, and i want the table to be named the same as the workbook.
    The below code creates the database and retrieves the filename of the workbook without the extension and saves it in the vairable FileNameNoExt which in turn is being used in the SQL create table to name it accordingly, but its not creating a table. No error appears, but nothings being created

    Please Login or Register  to view this content.
    Does anyone have any idea why the table isnt being created in the database 'SOA'?

    Many Thanks

    Dave

  2. #2
    Valued Forum Contributor
    Join Date
    08-26-2006
    Location
    -
    MS-Off Ver
    2010
    Posts
    388
    No error appears, but nothings being created
    This is because of the statement 'On Error Resume Next'. This ignores any errors and the code continues to the next line.
    Add the Err object to the Watch Window to see any errors while single-stepping the code.

    Does anyone have any idea why the table isnt being created in the database 'SOA'?
    There could be a syntax error in the CREATE TABLE statement.

    Does variable FileNameNoExt contain spaces?
    If it does try adding square brackets around the table name: "CREATE TABLE [" & FileNameNoExt & "].........

  3. #3
    Registered User
    Join Date
    07-25-2008
    Location
    England
    Posts
    8
    Ah Fantastic T-J

    I didnt think the file name had any spaces, but those brackets worked!

    Many thanks for your help!

    Dave

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1