Results 1 to 4 of 4

Creating Access tables with table names from excel cells

Threaded View

  1. #1
    Registered User
    Join Date
    08-01-2013
    Location
    Riyadh, Saudi Arabia
    MS-Off Ver
    Excel 2010
    Posts
    5

    Creating Access tables with table names from excel cells

    Hi,

    I want to create Access tables with table names taken from a range of cells in excel.
    I am not using the VBA variable in SQL statement correctly. Please see the FOR NEXT construct in the code below
    I tried this but doesn't work

    Sub ADOCreatenewtables()
    On Error Resume Next
    Dim cnn As ADODB.Connection
    Dim cmd As ADODB.Command
    Dim X As String
    strDBName = "ADO2.accdb"
    strMyPath = ThisWorkbook.Path
    strDB = strMyPath & "\" & strDBName
    
    ' open the connection
    Set cnn = New ADODB.Connection
    With cnn
    .Provider = "Microsoft.ACE.OLEDB.12.0"
    .Open strDB
    End With
    
    For Each Cell In Range("K1:K3")
    X = Cell.Value
    Set cmd = New ADODB.Command
    Set cmd.ActiveConnection = cnn
    'create Table
    cmd.CommandText = "CREATE TABLE 'X' (Style Char(10) Primary Key, A int, B int, C Int, RecActive YesNo)"
    cmd.Execute , , adCmdText
    Next Cell
    Set cmd = Nothing
    Set cnn = Nothing
    Exit Sub
    End Sub
    Last edited by alansidman; 01-18-2016 at 07:00 PM. Reason: code tags added

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Excel 2010 userform to access and edit the data in MS ACCESS DB tables
    By anand_y59 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-10-2012, 07:46 AM
  2. How to get table names from access to free text?
    By Baker in forum Access Programming / VBA / Macros
    Replies: 0
    Last Post: 03-15-2012, 08:10 PM
  3. [SOLVED] SQL in Access won't allow Multiple Tables using Create Table
    By danny2000 in forum Access Programming / VBA / Macros
    Replies: 2
    Last Post: 05-05-2009, 04:36 AM
  4. Obtain Access Table Names via Excel
    By Macdave_19 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-21-2008, 04:02 AM
  5. Retreiving list of table & field names from Access into Excel using VBA
    By shivboy in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-15-2006, 03:09 AM
  6. [SOLVED] Excel Spreadsheet from Access. List of names changes as names are
    By Gordy w/Hi Expectations in forum Excel General
    Replies: 1
    Last Post: 10-20-2005, 11:05 PM
  7. [SOLVED] Get names from Access table
    By Tempy in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-20-2005, 12:06 PM
  8. [SOLVED] Creating an access table with ADO
    By JJ in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-10-2005, 06:06 AM

Tags for this Thread

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