473,395 Members | 1,458 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,395 software developers and data experts.

Table field property change

553 512MB
If we have 2 tables, which are linked to each other

And i want to change property of a field in one of the tables i.e Max Character Length, etc
how would i do it - becasue Ms Access doesn't us doing it on a table which is linked to another one ?

Do we have to remove the link first or there is any other way at all

Thanks
Jul 11 '07 #1
6 6632
missinglinq
3,532 Expert 2GB
What version of Access are you using? And what exactly do you mean by linked tables? I ask because people have different ideas about what this means. If you mean that the tables are related, I can't reproduce the problem, as stated, in Access 2000. If you're decreasing the field length, you'll get a warning telling you that data may be loss, which may cause validation rules to be violated, but you can go ahead and do it. If the field involved is part of that relationship, i.e. the Primary Key in one table and the Foreign Key in the other, then yes, you have to remove the relationship, change the field lengths in both tables so that they match, them create the relationship again.

Good Luck!

Linq ;0)>
Jul 11 '07 #2
ADezii
8,834 Expert 8TB
If we have 2 tables, which are linked to each other

And i want to change property of a field in one of the tables i.e Max Character Length, etc
how would i do it - becasue Ms Access doesn't us doing it on a table which is linked to another one ?

Do we have to remove the link first or there is any other way at all

Thanks
You cannot change the Property of a Field in a Linked Table from the Current Database, Access simply will not allow it. One Method I use, however, is Automation code to modify a Field(s) programmatically from the Current Database without Deleting the existing Link. The following code will change the Field [Topics] in C:\Test\Testlink.mdb and make it Text 50. Let me nkow how you make out:
Expand|Select|Wrap|Line Numbers
  1. Dim strDB As String, MySQL As String
  2.  
  3. Dim appAccess As Access.Application
  4.  
  5. 'Path to External Database
  6. Const strConPathToExtDB = "C:\Test\Testlink.mdb"
  7.  
  8. 'Create new instance of Microsoft Access.
  9. Set appAccess = CreateObject("Access.Application")
  10.  
  11. 'Open database in Microsoft Access window.
  12. appAccess.OpenCurrentDatabase strConPathToExtDB
  13.  
  14. 'tblTopics - Table containing the Field (Topic) to modify
  15. 'after executing the SQL Statement, [Topic] is now a TEXT (50) Data Type
  16. MySQL = "ALTER TABLE tblTopics ALTER COLUMN Topic TEXT (50);"
  17. appAccess.DoCmd.RunSQL MySQL
  18.  
  19. appAccess.CloseCurrentDatabase
  20. Set appAccess = Nothing
Jul 12 '07 #3
questionit
553 512MB
HI

I am new in VB.

Can i write this code in the same .mdb file which is currently i have opened ?

Also, would that code go in a class module, etc and how will i run it?

Thanks


You cannot change the Property of a Field in a Linked Table from the Current Database, Access simply will not allow it. One Method I use, however, is Automation code to modify a Field(s) programmatically from the Current Database without Deleting the existing Link. The following code will change the Field [Topics] in C:\Test\Testlink.mdb and make it Text 50. Let me nkow how you make out:
Expand|Select|Wrap|Line Numbers
  1. Dim strDB As String, MySQL As String
  2.  
  3. Dim appAccess As Access.Application
  4.  
  5. 'Path to External Database
  6. Const strConPathToExtDB = "C:\Test\Testlink.mdb"
  7.  
  8. 'Create new instance of Microsoft Access.
  9. Set appAccess = CreateObject("Access.Application")
  10.  
  11. 'Open database in Microsoft Access window.
  12. appAccess.OpenCurrentDatabase strConPathToExtDB
  13.  
  14. 'tblTopics - Table containing the Field (Topic) to modify
  15. 'after executing the SQL Statement, [Topic] is now a TEXT (50) Data Type
  16. MySQL = "ALTER TABLE tblTopics ALTER COLUMN Topic TEXT (50);"
  17. appAccess.DoCmd.RunSQL MySQL
  18.  
  19. appAccess.CloseCurrentDatabase
  20. Set appAccess = Nothing
Jul 12 '07 #4
ADezii
8,834 Expert 8TB
HI

I am new in VB.

Can i write this code in the same .mdb file which is currently i have opened ?

Also, would that code go in a class module, etc and how will i run it?

Thanks
Can i write this code in the same .mdb file which is currently i have opened ?
You most certainly can.
Also, would that code go in a class module, etc and how will i run it?
Do not put the Code in a Traditional Class Module. The code can be placed in a Function or Sub-Routine Procedure, it can be executed from the Click() Event of a Command Button, AfterUpdate() Event of a Control, Open() Event of a Form, etc.
Jul 12 '07 #5
questionit
553 512MB
Hi

I've tried your code but got this run-time error: '3720' - Cannot change field 'Name'. It is part of one or more relationships
You most certainly can.

How did you run it successfully ?

Do not put the Code in a Traditional Class Module. The code can be placed in a Function or Sub-Routine Procedure, it can be executed from the Click() Event of a Command Button, AfterUpdate() Event of a Control, Open() Event of a Form, etc.
Jul 13 '07 #6
ADezii
8,834 Expert 8TB
Hi

I've tried your code but got this run-time error: '3720' - Cannot change field 'Name'. It is part of one or more relationships
The Field(s) I ran the code against were not part of any Relationship. As the Runtime Error indicates, I do not think that you can change certain characteristics of a Field if it is part of a Relationship. The Relationship would have to be Deleted, the Field characteristic would have to modified, and then the Relationship would have to be re-established. Further Errors may occur depending on what changes you made, and if they involved Fields on both sides of the Relationship. This can be done programmatically but it would be a challenge and not be without risk. You may find yourself in a situation where you cannot Re-link the Tables involved in the Relationship after making the modifications.
Jul 13 '07 #7

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

Similar topics

2
by: LaurenW | last post by:
Hi folks, I just discovered that I have a table with a bunch of text fields that ALL have the "Allow Zero Length" property set to "No", which is apparently the default when you create a new text...
4
by: John Baker | last post by:
Hi: I am having a problem making the impact a field property change in a table trickle through to a report. Between the table and the report are numerous queries and sums. I have changed the...
10
by: MLH | last post by:
I have an A97 table with a Yes/No field named TowJob and a form bound to that table. The TowJob control on the form is bound to the same field. It is an option group with Yes and No bttns valued...
2
by: MLH | last post by:
In design view, say you habitually type descriptions for each of the table fields you create. After many moons, many many tables and many many many fields - you wanna delete each and every table...
2
by: Greg Strong | last post by:
Hello All, Is it possible to change table field lookup properties in code? I've been able to change other field properties in code, however so far no luck with field lookup properties. What...
6
by: mukesh | last post by:
Hi, I have a field in a table the property of which i have set as a general number with 3 decimal places. I want to enter a weight 1.265 tons but the decimal place do not work.The number gets...
2
by: mukesh | last post by:
Can we use expression in default value for a table field for example – IIf(Table-1.field-1=table-2 . field-1, table-1.field-2, 0) Interpretation – If field-1 of table -1 is like/equal to...
1
by: ad | last post by:
I want to change a field a SQLServer table to varchar(10) if it is nvarchar(5). How can I determinate the data type of a physical table field in SQLServer 2005?
1
by: STUFIX | last post by:
Hi, I need to change a field name in a table stored on a backend database that is used by various queries, forms, etc on the front end client via a linked table. I can't work out how to change...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.