Solved

Altering a MSSQL table from Microsoft Access via DAO

Posted on 2013-01-10
2
317 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
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.

895 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

18 Experts available now in Live!

Get 1:1 Help Now