• Running DDL on a SQL backend

    Author
    Topic
    #459961

    I want to run a DDL query to add a field to a table in a SQL server database from VBA using a DSN but I can’t figure out how to run it. This is what I have so far –

    Dim cn As ADODB.Connection
    Set cn = New ADODB.Connection
    cn.Open “dsn=MyData”
    strSQL = “ALTER TABLE Customer ADD UploadTime SMALLDATETIME”

    so how do I execute this statement against the connection?

    Viewing 0 reply threads
    Author
    Replies
    • #1161320

      I’d change the SQL to

      strSQL = “ALTER TABLE Customer ADD COLUMN UploadTime SMALLDATETIME”

      You can execute it by using the Execute method of the connection:

      cn.Execute strSQL

      • #1161321

        Thanks Hans – really easy when you know!
        It didn’t like the ‘COLUMN’

        • #1161322

          It didn’t like the ‘COLUMN’

          Apparently the SQL Server version of SQL is slightly different from that in Access.

          • #1161323

            Next probem – I can’t see the changes in Access until I delete and reattach.
            any suggestions on how to refresh the link?
            or do I need to drop the connection and then transferdatabase aclink to reattach?

            • #1161326

              It’s probably best to delete and recreate the linked table.

    Viewing 0 reply threads
    Reply To: Running DDL on a SQL backend

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: