My Assistant
![]() ![]() |
|
|
Sep 14 2011, 06:26 AM
Post
#1
|
|
|
UtterAccess Addict Posts: 293 |
Hi, I am trying to use the ALTER TABLE, ALTER COLUMN command in vba to set required=no of an existing table but can't figure out how to do it.
Here is the code I currently have. What needs to go inplace of ....? Thanks CODE Dim cnn As New ADODB.Connection
LinkPathFile = Mid(FindSource(), 11) With cnn .Open "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = " & LinkPathFile .Execute "ALTER TABLE tblRequests ALTER COLUMN RequestFee ....." .Close End With |
|
|
|
Sep 14 2011, 10:56 AM
Post
#2
|
|
|
Retired Moderator Posts: 19,667 |
Try NULL in place of ....
|
|
|
|
Sep 14 2011, 11:09 AM
Post
#3
|
|
|
UtterAccess Addict Posts: 293 |
I've tried that, I get Syntax Error in field definition.
|
|
|
|
Sep 14 2011, 11:51 AM
Post
#4
|
|
|
Retired Moderator Posts: 19,667 |
Sorry... I was thinking of T-SQL.
I normally use DAO Field Object to alter the Required Property of the JET Table Field istead of ADO + JET DDL. An alternative is to use ADOX. See UA Topic Code Library Form with lst/cbo RowSource pointing to FE and follow the links to the 2 MSDN articles posted by Brent for more info. |
|
|
|
Sep 14 2011, 12:18 PM
Post
#5
|
|
|
UtterAccess Addict Posts: 293 |
Thanks for the link. I've read that and will use DAO, but could do with some sample code as the code I had I had copied from elsewhere, so it's a bit beyond me.
|
|
|
|
Sep 14 2011, 12:38 PM
Post
#6
|
|
|
Retired Moderator Posts: 19,667 |
Check Access VBA/DAO Help on the Required Property of a Field Object for detailed explanation and proper sample code but basically, you can do with 1 statement:
CurrentDb.TableDefs("YourTable").Fields("YourField").Required = False |
|
|
|
Sep 14 2011, 01:37 PM
Post
#7
|
|
|
UtterAccess Addict Posts: 293 |
Had to make add some more code as i'm using a linked table, but I got it working.
Many Thanks for your help. |
|
|
|
Sep 14 2011, 08:33 PM
Post
#8
|
|
|
Retired Moderator Posts: 19,667 |
You're welcome... Glad to help...
|
|
|
|
Jan 10 2013, 07:00 AM
Post
#9
|
|
|
UtterAccess Enthusiast Posts: 67 |
Had to make add some more code as i'm using a linked table, but I got it working. Many Thanks for your help. @ddaddy Could you let me know the additional code required to get this working with linked tables please as I have the same problem. ie how to change the "Required" property of a column in a linked table. Thanks Darwood |
|
|
|
![]() ![]() |
|
Go to Top · Lo-Fi Version | Time is now: 21st May 2013 - 07:36 PM |