Link to home
Start Free TrialLog in
Avatar of James
JamesFlag for Canada

asked on

Altering a MSSQL table from Microsoft Access via DAO

I have a support database in Access that I've used for years to alter the structure of a MSSQL database. Up until now, the code used ADO to do that but, thanks to some internal IT changes at my client, ADO is no longer allowed. They are insisting on DAO.

Here's the original ADO code. In this example, it is changing the length of field PONumber in table tblOrders to 20.

-------------------------------------------------------

Private Sub cmdAlter_Click()
Dim strSQL As String
Dim oConn As ADODB.Connection


    Set oConn = New ADODB.Connection
        oConn.Open "Driver={SQL Server};" & _
                   "Server=" & Me.servername & ";" & _
                   "Database=" & Me.databasename & ";" & _
                   "Uid=" & Me.username & ";" & _
                   "Pwd=" & Me.password & ""

   
    strSQL = "ALTER TABLE dbo.tblOrders ALTER COLUMN PONumber nvarchar(20)";"
    oConn.Execute strSQL

oConn.Close

End Sub

-------------------------------------------------------

Can the same thing be done in DAO?

Thanks!

James
Avatar of jerryb30
jerryb30
Flag of United States of America image

Why not use a pass-through query?
ASKER CERTIFIED SOLUTION
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial