I have been looking after an MS Access database, using table links to
access data in a back-end MDB database. We have recently micrated to a
SQL Server 2000 back-end atabase, once again accessing it though table links.
I am comfortable with the data side of things (whether through table
links or an adodb.recordset). What I am missing, however, is all the
useful things you could do to automatically maintain a back-end database
from a front-end database via the DAO 'Database' Object which exposes
the TableDefs Collection, the TableDef Object, the Fields Collection, the
Field, the Indexes Collection and the Index object.
Is there any way I can, from an Access 2000 front-end database, connect
to a SQL Server 2000 database as a 'database' to perform the tasks in the
following procedures. -
-
Private Sub SetBackEndDatabase(db As Database)
-
Set db = _
-
OpenDatabase("w:\backend\backend.mdb", False, False, ";PWD=" & "BackEndDatabasePassword")
-
End Sub
-
-
Private Sub ModifyField(db, udtFieldProperties As FieldProps)
-
Dim tdf As TableDef, fld As Field
-
With udtFieldProperties
-
Set tdf = db.TableDefs(.TableName)
-
Set fld = tdf.Fields(.FieldName)
-
If .FieldType = dbText Then
-
fld.AllowZeroLength = .FieldAllowZeroLength
-
End If
-
fld.Required = .FieldRequired
-
End With
-
db.TableDefs.Refresh
-
End Sub
-
-
Private Sub CreateIndexInExistingTable(db, udtFieldProperties As FieldProps)
-
Dim tdf As TableDef
-
Set tdf = db.TableDefs(udtFieldProperties.TableName)
-
CreateIndex tdf, udtFieldProperties
-
End Sub
-
-
Private Sub CreateFieldInExistingTable(db, udtFieldProperties As FieldProps)
-
Dim tdf As TableDef
-
Set tdf = db.TableDefs(udtFieldProperties.TableName)
-
CreateField tdf, udtFieldProperties
-
End Sub
-
-
Private Sub RenameField(db As Database, ByVal strTableName As String, ByVal _
-
strOriginalFieldName As String, ByVal strNewFieldName As String)
-
Dim tdf As TableDef, fld As Field
-
Set tdf = db.TableDefs(strTableName)
-
Set fld = tdf.Fields(strOriginalFieldName)
-
fld.Name = strNewFieldName
-
db.TableDefs.Refresh
-
End Sub
-
-
Private Sub RenameIndex(db As Database, ByVal strTableName As String, ByVal _
-
strOriginalIndexName As String, ByVal strNewIndexName As String)
-
Dim tdf As TableDef, idx As Index
-
Set tdf = db.TableDefs(strTableName)
-
Set idx = tdf.Indexes(strOriginalIndexName)
-
idx.Name = strNewIndexName
-
db.TableDefs.Refresh
-
End Sub
-
-
Private Sub RenameTable(db As Database, ByVal strOriginalTableName As String, _
-
ByVal strNewTableName As String)
-
Dim tdf As TableDef
-
Set tdf = db.TableDefs(strOriginalTableName)
-
tdf.Name = strNewTableName
-
db.TableDefs.Refresh
-
End Sub
-
-
Private Sub DeleteField(db As Database, ByVal strTableName As String, _
-
ByVal strFieldName As String)
-
Dim tdf As TableDef
-
Const conItemNotFoundInThisCollection = 3265
-
On Error GoTo XEH
-
Set tdf = db.TableDefs(strTableName)
-
tdf.Fields.Delete (strFieldName)
-
db.TableDefs.Refresh
-
XEH: If Err = conItemNotFoundInThisCollection Then Exit Sub
-
End Sub
-
-
Private Sub DeleteIndex(db As Database, ByVal strTableName As String, ByVal _
-
strIndexName As String)
-
Dim tdf As TableDef
-
Const conItemNotFoundInThisCollection = 3265
-
On Error GoTo XEH
-
Set tdf = db.TableDefs(strTableName)
-
tdf.Indexes.Delete (strIndexName)
-
db.TableDefs.Refresh
-
XEH: If Err = conItemNotFoundInThisCollection Then Exit Sub
-
End Sub
-
-
Private Sub DeleteTable(db As Database, ByVal strTableName As String)
-
Const conItemNotFoundInThisCollection = 3265
-
On Error GoTo XEH
-
db.TableDefs.Delete (strTableName)
-
db.TableDefs.Refresh
-
XEH: If Err = conItemNotFoundInThisCollection Then Exit Sub
-
End Sub
-
-
Private Sub CreateTable(db As Database, udtFieldProperties() As FieldProps)
-
Dim tdf As TableDef, i As Long
-
Set tdf = db.CreateTableDef(udtFieldProperties(1).TableName)
-
For i = 1 To UBound(udtFieldProperties)
-
CreateField tdf, udtFieldProperties(i)
-
If udtFieldProperties(i).FieldIdx <> "None" Then
-
CreateIndex tdf, udtFieldProperties(i)
-
End If
-
Next i
-
db.TableDefs.Append tdf
-
db.TableDefs.Refresh
-
End Sub
-
-
Private Sub CreateField(ByVal tdf As TableDef, udtFieldProperties As FieldProps)
-
Dim fld As Field
-
With udtFieldProperties
-
Set fld = tdf.CreateField(.FieldName, .FieldType, .FieldSize)
-
If .FieldType = dbText Then
-
fld.AllowZeroLength = .FieldAllowZeroLength
-
End If
-
fld.Required = .FieldRequired
-
End With
-
tdf.Fields.Append fld
-
tdf.Fields.Refresh
-
End Sub
-
-
Private Sub CreateIndex(ByVal tdf As TableDef, udtFieldProperties As FieldProps)
-
Dim idx As Index, idxfld As Field
-
With udtFieldProperties
-
Set idx = tdf.CreateIndex("IDX_" & .FieldName)
-
Set idxfld = idx.CreateField(.FieldName)
-
idx.Fields.Append idxfld
-
If .FieldIdx = "Primary" Then
-
idx.Primary = True
-
idx.Required = True
-
End If
-
If .FieldIdx = "Primary" Or .FieldIdx = "Unique" Then
-
idx.Unique = True
-
End If
-
tdf.Indexes.Append idx
-
tdf.Indexes.Refresh
-
End With
-
End Sub
-
-
2 2177 PEB 1,418
Expert 1GB
As I see u want to modify the backend database using the front end application!
I'm pretty sure that with ADO db can't be done! But sure u can do it with Pass trought SQL expressions - only u pass the respective SQL in SQL server directly to it! And it modifies the fields tables and structures!
I have been looking after an MS Access database, using table links to
access data in a back-end MDB database. We have recently micrated to a
SQL Server 2000 back-end atabase, once again accessing it though table links.
I am comfortable with the data side of things (whether through table
links or an adodb.recordset). What I am missing, however, is all the
useful things you could do to automatically maintain a back-end database
from a front-end database via the DAO 'Database' Object which exposes
the TableDefs Collection, the TableDef Object, the Fields Collection, the
Field, the Indexes Collection and the Index object.
Is there any way I can, from an Access 2000 front-end database, connect
to a SQL Server 2000 database as a 'database' to perform the tasks in the
following procedures. -
-
Private Sub SetBackEndDatabase(db As Database)
-
Set db = _
-
OpenDatabase("w:\backend\backend.mdb", False, False, ";PWD=" & "BackEndDatabasePassword")
-
End Sub
-
-
Private Sub ModifyField(db, udtFieldProperties As FieldProps)
-
Dim tdf As TableDef, fld As Field
-
With udtFieldProperties
-
Set tdf = db.TableDefs(.TableName)
-
Set fld = tdf.Fields(.FieldName)
-
If .FieldType = dbText Then
-
fld.AllowZeroLength = .FieldAllowZeroLength
-
End If
-
fld.Required = .FieldRequired
-
End With
-
db.TableDefs.Refresh
-
End Sub
-
-
Private Sub CreateIndexInExistingTable(db, udtFieldProperties As FieldProps)
-
Dim tdf As TableDef
-
Set tdf = db.TableDefs(udtFieldProperties.TableName)
-
CreateIndex tdf, udtFieldProperties
-
End Sub
-
-
Private Sub CreateFieldInExistingTable(db, udtFieldProperties As FieldProps)
-
Dim tdf As TableDef
-
Set tdf = db.TableDefs(udtFieldProperties.TableName)
-
CreateField tdf, udtFieldProperties
-
End Sub
-
-
Private Sub RenameField(db As Database, ByVal strTableName As String, ByVal _
-
strOriginalFieldName As String, ByVal strNewFieldName As String)
-
Dim tdf As TableDef, fld As Field
-
Set tdf = db.TableDefs(strTableName)
-
Set fld = tdf.Fields(strOriginalFieldName)
-
fld.Name = strNewFieldName
-
db.TableDefs.Refresh
-
End Sub
-
-
Private Sub RenameIndex(db As Database, ByVal strTableName As String, ByVal _
-
strOriginalIndexName As String, ByVal strNewIndexName As String)
-
Dim tdf As TableDef, idx As Index
-
Set tdf = db.TableDefs(strTableName)
-
Set idx = tdf.Indexes(strOriginalIndexName)
-
idx.Name = strNewIndexName
-
db.TableDefs.Refresh
-
End Sub
-
-
Private Sub RenameTable(db As Database, ByVal strOriginalTableName As String, _
-
ByVal strNewTableName As String)
-
Dim tdf As TableDef
-
Set tdf = db.TableDefs(strOriginalTableName)
-
tdf.Name = strNewTableName
-
db.TableDefs.Refresh
-
End Sub
-
-
Private Sub DeleteField(db As Database, ByVal strTableName As String, _
-
ByVal strFieldName As String)
-
Dim tdf As TableDef
-
Const conItemNotFoundInThisCollection = 3265
-
On Error GoTo XEH
-
Set tdf = db.TableDefs(strTableName)
-
tdf.Fields.Delete (strFieldName)
-
db.TableDefs.Refresh
-
XEH: If Err = conItemNotFoundInThisCollection Then Exit Sub
-
End Sub
-
-
Private Sub DeleteIndex(db As Database, ByVal strTableName As String, ByVal _
-
strIndexName As String)
-
Dim tdf As TableDef
-
Const conItemNotFoundInThisCollection = 3265
-
On Error GoTo XEH
-
Set tdf = db.TableDefs(strTableName)
-
tdf.Indexes.Delete (strIndexName)
-
db.TableDefs.Refresh
-
XEH: If Err = conItemNotFoundInThisCollection Then Exit Sub
-
End Sub
-
-
Private Sub DeleteTable(db As Database, ByVal strTableName As String)
-
Const conItemNotFoundInThisCollection = 3265
-
On Error GoTo XEH
-
db.TableDefs.Delete (strTableName)
-
db.TableDefs.Refresh
-
XEH: If Err = conItemNotFoundInThisCollection Then Exit Sub
-
End Sub
-
-
Private Sub CreateTable(db As Database, udtFieldProperties() As FieldProps)
-
Dim tdf As TableDef, i As Long
-
Set tdf = db.CreateTableDef(udtFieldProperties(1).TableName)
-
For i = 1 To UBound(udtFieldProperties)
-
CreateField tdf, udtFieldProperties(i)
-
If udtFieldProperties(i).FieldIdx <> "None" Then
-
CreateIndex tdf, udtFieldProperties(i)
-
End If
-
Next i
-
db.TableDefs.Append tdf
-
db.TableDefs.Refresh
-
End Sub
-
-
Private Sub CreateField(ByVal tdf As TableDef, udtFieldProperties As FieldProps)
-
Dim fld As Field
-
With udtFieldProperties
-
Set fld = tdf.CreateField(.FieldName, .FieldType, .FieldSize)
-
If .FieldType = dbText Then
-
fld.AllowZeroLength = .FieldAllowZeroLength
-
End If
-
fld.Required = .FieldRequired
-
End With
-
tdf.Fields.Append fld
-
tdf.Fields.Refresh
-
End Sub
-
-
Private Sub CreateIndex(ByVal tdf As TableDef, udtFieldProperties As FieldProps)
-
Dim idx As Index, idxfld As Field
-
With udtFieldProperties
-
Set idx = tdf.CreateIndex("IDX_" & .FieldName)
-
Set idxfld = idx.CreateField(.FieldName)
-
idx.Fields.Append idxfld
-
If .FieldIdx = "Primary" Then
-
idx.Primary = True
-
idx.Required = True
-
End If
-
If .FieldIdx = "Primary" Or .FieldIdx = "Unique" Then
-
idx.Unique = True
-
End If
-
tdf.Indexes.Append idx
-
tdf.Indexes.Refresh
-
End With
-
End Sub
-
-
NeoPa 32,556
Expert Mod 16PB
Sam,
If you have a question to ask - please give specifics.
The tasks you want done need to be described clearly in your question. Expecting the experts to dig through your code to save you the trouble is not how it should work.
PEB's answer probably gives you the information you need I suspect, however. You will need the expertise to handle the TSQL side of things obviously. We have a SQL Server forum where our experts will be happy to give further assistance if requested.
Good luck in your project.
MODERATOR.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Denis |
last post by:
Hi
I am planning to design a database (destined for the web) that will have
between 20000 and 45000 records in it and will receive a lot of reads but
very very few writes (just from me).
Now...
|
by: Bon |
last post by:
Hello all
Would it be possible to migrate the MS Access 2000 to MS SQL Server
2000?
My application is using MS Access 2000 as database and as user
interface such as forms. Now, I want to...
|
by: Squirrel |
last post by:
I've developed an Access 2002 database which will be deployed with the
backend on
a server and frontend on the users' PCs. I've now been advised that new
employees will
be given laptops with...
|
by: Michael |
last post by:
I am using MS Access 2000 on an Windows XP machine and am trying to
use
the Upsizing Tool in Access 2000 to upsize an Access 2000 database to
use with Microsoft SQL Server 7.0.
My MS Access...
|
by: Uwe Range |
last post by:
Hi to all!
A customer of mine told me some days ago that her IT-people told her
ACCESS would not be such a good idea for continuing with our project,
because Access will not be continued in the...
|
by: lcifers |
last post by:
First off, sorry if my cross posting offends anyone. I'm posting this
in Access and SQL Server groups - not sure which one is appropriate.
I have a relatively simple ASP.NET/VB.NET application...
|
by: DaveG |
last post by:
Hi all
I am planning on writing a stock and accounts program for the family
business, I understand this is likely to take close to 2 years to
accomplish. The stock is likely to run into over a...
|
by: Mo |
last post by:
Hello all,
I'm trying to set up an access 2000 .adp project connecting to a SQL
server 2005 database. I can set up the connection ok, but once I have
completed the setup process, I get the...
|
by: yolenman |
last post by:
Hello -
This is my first posting to this group, so please bear with me. Also note, that while I'm intelligent, databases are not in my field of knowledge.
I'm working with a small limousine...
|
by: JA |
last post by:
Is it possible to connect to Sql Server 2005 using an Access 2000 adp? I
keep trying, but it doesn't want to accept my id, even though it is right.
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |