473,386 Members | 1,674 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Use of DAO In MS Access 2000 With a SQL Server 2000 DB

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.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub SetBackEndDatabase(db As Database)
  3. Set db = _
  4. OpenDatabase("w:\backend\backend.mdb", False, False, ";PWD=" & "BackEndDatabasePassword")
  5. End Sub
  6.  
  7. Private Sub ModifyField(db, udtFieldProperties As FieldProps)
  8. Dim tdf As TableDef, fld As Field
  9. With udtFieldProperties
  10.   Set tdf = db.TableDefs(.TableName)
  11.   Set fld = tdf.Fields(.FieldName)
  12.   If .FieldType = dbText Then
  13.     fld.AllowZeroLength = .FieldAllowZeroLength
  14.   End If
  15.   fld.Required = .FieldRequired
  16. End With
  17. db.TableDefs.Refresh
  18. End Sub
  19.  
  20. Private Sub CreateIndexInExistingTable(db, udtFieldProperties As FieldProps)
  21. Dim tdf As TableDef
  22. Set tdf = db.TableDefs(udtFieldProperties.TableName)
  23. CreateIndex tdf, udtFieldProperties
  24. End Sub
  25.  
  26. Private Sub CreateFieldInExistingTable(db, udtFieldProperties As FieldProps)
  27. Dim tdf As TableDef
  28. Set tdf = db.TableDefs(udtFieldProperties.TableName)
  29. CreateField tdf, udtFieldProperties
  30. End Sub
  31.  
  32. Private Sub RenameField(db As Database, ByVal strTableName As String, ByVal _
  33. strOriginalFieldName As String, ByVal strNewFieldName As String)
  34. Dim tdf As TableDef, fld As Field
  35. Set tdf = db.TableDefs(strTableName)
  36. Set fld = tdf.Fields(strOriginalFieldName)
  37. fld.Name = strNewFieldName
  38. db.TableDefs.Refresh
  39. End Sub
  40.  
  41. Private Sub RenameIndex(db As Database, ByVal strTableName As String, ByVal _
  42. strOriginalIndexName As String, ByVal strNewIndexName As String)
  43. Dim tdf As TableDef, idx As Index
  44. Set tdf = db.TableDefs(strTableName)
  45. Set idx = tdf.Indexes(strOriginalIndexName)
  46. idx.Name = strNewIndexName
  47. db.TableDefs.Refresh
  48. End Sub
  49.  
  50. Private Sub RenameTable(db As Database, ByVal strOriginalTableName As String, _
  51. ByVal strNewTableName As String)
  52. Dim tdf As TableDef
  53. Set tdf = db.TableDefs(strOriginalTableName)
  54. tdf.Name = strNewTableName
  55. db.TableDefs.Refresh
  56. End Sub
  57.  
  58. Private Sub DeleteField(db As Database, ByVal strTableName As String, _
  59. ByVal strFieldName As String)
  60. Dim tdf As TableDef
  61. Const conItemNotFoundInThisCollection = 3265
  62. On Error GoTo XEH
  63. Set tdf = db.TableDefs(strTableName)
  64. tdf.Fields.Delete (strFieldName)
  65. db.TableDefs.Refresh
  66. XEH: If Err = conItemNotFoundInThisCollection Then Exit Sub
  67. End Sub
  68.  
  69. Private Sub DeleteIndex(db As Database, ByVal strTableName As String, ByVal _
  70. strIndexName As String)
  71. Dim tdf As TableDef
  72. Const conItemNotFoundInThisCollection = 3265
  73. On Error GoTo XEH
  74. Set tdf = db.TableDefs(strTableName)
  75. tdf.Indexes.Delete (strIndexName)
  76. db.TableDefs.Refresh
  77. XEH: If Err = conItemNotFoundInThisCollection Then Exit Sub
  78. End Sub
  79.  
  80. Private Sub DeleteTable(db As Database, ByVal strTableName As String)
  81. Const conItemNotFoundInThisCollection = 3265
  82. On Error GoTo XEH
  83. db.TableDefs.Delete (strTableName)
  84. db.TableDefs.Refresh
  85. XEH: If Err = conItemNotFoundInThisCollection Then Exit Sub
  86. End Sub
  87.  
  88. Private Sub CreateTable(db As Database, udtFieldProperties() As FieldProps)
  89. Dim tdf As TableDef, i As Long
  90. Set tdf = db.CreateTableDef(udtFieldProperties(1).TableName)
  91. For i = 1 To UBound(udtFieldProperties)
  92.   CreateField tdf, udtFieldProperties(i)
  93.   If udtFieldProperties(i).FieldIdx <> "None" Then
  94.     CreateIndex tdf, udtFieldProperties(i)
  95.   End If
  96. Next i
  97. db.TableDefs.Append tdf
  98. db.TableDefs.Refresh
  99. End Sub
  100.  
  101. Private Sub CreateField(ByVal tdf As TableDef, udtFieldProperties As FieldProps)
  102. Dim fld As Field
  103. With udtFieldProperties
  104.   Set fld = tdf.CreateField(.FieldName, .FieldType, .FieldSize)
  105.   If .FieldType = dbText Then
  106.     fld.AllowZeroLength = .FieldAllowZeroLength
  107.   End If
  108.   fld.Required = .FieldRequired
  109. End With
  110. tdf.Fields.Append fld
  111. tdf.Fields.Refresh
  112. End Sub
  113.  
  114. Private Sub CreateIndex(ByVal tdf As TableDef, udtFieldProperties As FieldProps)
  115. Dim idx As Index, idxfld As Field
  116. With udtFieldProperties
  117.   Set idx = tdf.CreateIndex("IDX_" & .FieldName)
  118.   Set idxfld = idx.CreateField(.FieldName)
  119.   idx.Fields.Append idxfld 
  120.   If .FieldIdx = "Primary" Then
  121.     idx.Primary = True
  122.     idx.Required = True
  123.   End If
  124.   If .FieldIdx = "Primary" Or .FieldIdx = "Unique" Then
  125.     idx.Unique = True
  126.   End If
  127.   tdf.Indexes.Append idx
  128.   tdf.Indexes.Refresh
  129. End With
  130. End Sub
  131.  
  132.  
Jan 9 '07 #1
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.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub SetBackEndDatabase(db As Database)
  3. Set db = _
  4. OpenDatabase("w:\backend\backend.mdb", False, False, ";PWD=" & "BackEndDatabasePassword")
  5. End Sub
  6.  
  7. Private Sub ModifyField(db, udtFieldProperties As FieldProps)
  8. Dim tdf As TableDef, fld As Field
  9. With udtFieldProperties
  10.   Set tdf = db.TableDefs(.TableName)
  11.   Set fld = tdf.Fields(.FieldName)
  12.   If .FieldType = dbText Then
  13.     fld.AllowZeroLength = .FieldAllowZeroLength
  14.   End If
  15.   fld.Required = .FieldRequired
  16. End With
  17. db.TableDefs.Refresh
  18. End Sub
  19.  
  20. Private Sub CreateIndexInExistingTable(db, udtFieldProperties As FieldProps)
  21. Dim tdf As TableDef
  22. Set tdf = db.TableDefs(udtFieldProperties.TableName)
  23. CreateIndex tdf, udtFieldProperties
  24. End Sub
  25.  
  26. Private Sub CreateFieldInExistingTable(db, udtFieldProperties As FieldProps)
  27. Dim tdf As TableDef
  28. Set tdf = db.TableDefs(udtFieldProperties.TableName)
  29. CreateField tdf, udtFieldProperties
  30. End Sub
  31.  
  32. Private Sub RenameField(db As Database, ByVal strTableName As String, ByVal _
  33. strOriginalFieldName As String, ByVal strNewFieldName As String)
  34. Dim tdf As TableDef, fld As Field
  35. Set tdf = db.TableDefs(strTableName)
  36. Set fld = tdf.Fields(strOriginalFieldName)
  37. fld.Name = strNewFieldName
  38. db.TableDefs.Refresh
  39. End Sub
  40.  
  41. Private Sub RenameIndex(db As Database, ByVal strTableName As String, ByVal _
  42. strOriginalIndexName As String, ByVal strNewIndexName As String)
  43. Dim tdf As TableDef, idx As Index
  44. Set tdf = db.TableDefs(strTableName)
  45. Set idx = tdf.Indexes(strOriginalIndexName)
  46. idx.Name = strNewIndexName
  47. db.TableDefs.Refresh
  48. End Sub
  49.  
  50. Private Sub RenameTable(db As Database, ByVal strOriginalTableName As String, _
  51. ByVal strNewTableName As String)
  52. Dim tdf As TableDef
  53. Set tdf = db.TableDefs(strOriginalTableName)
  54. tdf.Name = strNewTableName
  55. db.TableDefs.Refresh
  56. End Sub
  57.  
  58. Private Sub DeleteField(db As Database, ByVal strTableName As String, _
  59. ByVal strFieldName As String)
  60. Dim tdf As TableDef
  61. Const conItemNotFoundInThisCollection = 3265
  62. On Error GoTo XEH
  63. Set tdf = db.TableDefs(strTableName)
  64. tdf.Fields.Delete (strFieldName)
  65. db.TableDefs.Refresh
  66. XEH: If Err = conItemNotFoundInThisCollection Then Exit Sub
  67. End Sub
  68.  
  69. Private Sub DeleteIndex(db As Database, ByVal strTableName As String, ByVal _
  70. strIndexName As String)
  71. Dim tdf As TableDef
  72. Const conItemNotFoundInThisCollection = 3265
  73. On Error GoTo XEH
  74. Set tdf = db.TableDefs(strTableName)
  75. tdf.Indexes.Delete (strIndexName)
  76. db.TableDefs.Refresh
  77. XEH: If Err = conItemNotFoundInThisCollection Then Exit Sub
  78. End Sub
  79.  
  80. Private Sub DeleteTable(db As Database, ByVal strTableName As String)
  81. Const conItemNotFoundInThisCollection = 3265
  82. On Error GoTo XEH
  83. db.TableDefs.Delete (strTableName)
  84. db.TableDefs.Refresh
  85. XEH: If Err = conItemNotFoundInThisCollection Then Exit Sub
  86. End Sub
  87.  
  88. Private Sub CreateTable(db As Database, udtFieldProperties() As FieldProps)
  89. Dim tdf As TableDef, i As Long
  90. Set tdf = db.CreateTableDef(udtFieldProperties(1).TableName)
  91. For i = 1 To UBound(udtFieldProperties)
  92.   CreateField tdf, udtFieldProperties(i)
  93.   If udtFieldProperties(i).FieldIdx <> "None" Then
  94.     CreateIndex tdf, udtFieldProperties(i)
  95.   End If
  96. Next i
  97. db.TableDefs.Append tdf
  98. db.TableDefs.Refresh
  99. End Sub
  100.  
  101. Private Sub CreateField(ByVal tdf As TableDef, udtFieldProperties As FieldProps)
  102. Dim fld As Field
  103. With udtFieldProperties
  104.   Set fld = tdf.CreateField(.FieldName, .FieldType, .FieldSize)
  105.   If .FieldType = dbText Then
  106.     fld.AllowZeroLength = .FieldAllowZeroLength
  107.   End If
  108.   fld.Required = .FieldRequired
  109. End With
  110. tdf.Fields.Append fld
  111. tdf.Fields.Refresh
  112. End Sub
  113.  
  114. Private Sub CreateIndex(ByVal tdf As TableDef, udtFieldProperties As FieldProps)
  115. Dim idx As Index, idxfld As Field
  116. With udtFieldProperties
  117.   Set idx = tdf.CreateIndex("IDX_" & .FieldName)
  118.   Set idxfld = idx.CreateField(.FieldName)
  119.   idx.Fields.Append idxfld 
  120.   If .FieldIdx = "Primary" Then
  121.     idx.Primary = True
  122.     idx.Required = True
  123.   End If
  124.   If .FieldIdx = "Primary" Or .FieldIdx = "Unique" Then
  125.     idx.Unique = True
  126.   End If
  127.   tdf.Indexes.Append idx
  128.   tdf.Indexes.Refresh
  129. End With
  130. End Sub
  131.  
  132.  
Jan 9 '07 #2
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.
Jan 9 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
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...
4
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...
4
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...
3
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...
33
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...
2
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...
17
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...
5
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...
13
yolenman
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...
2
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.
0
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$) { } ...
0
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...
0
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...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
marktang
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,...
0
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...
0
Oralloy
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.