Solved

Altering a MSSQL table from Microsoft Access via DAO

Posted on 2013-01-10
2
316 Views
Last Modified: 2013-01-14
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
0
Comment
Question by:jrmcanada2
2 Comments
 
LVL 26

Expert Comment

by:jerryb30
ID: 38763131
Why not use a pass-through query?
0
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 350 total points
ID: 38763150
You can try this:

Dim db As DAO.Database
Set db=DAO.OpenDatabase("", False, False,"ODBC;DRIVER={SQL
SERVER};ADDRESS=ServerAddress;SERVER=ServerName;WSID=PC;DATABASE=DatabaseNameB;TRUSTED_CONNECTION=YES;UID=UserName;PWD=Password;NETWORK=DBMSSOCN")

I've not tried this in YEARS.

Why in the world would your customer not use ADO with SQL Server? DAO is generally slower when working with server based data ...
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now