472,334 Members | 1,533 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

How can I modify fields types via VBA code?

Hi to everyone! I'm new in this NG. I'm posting this message just for
learning how can I modify the type of a field in a table via VBA code.
Is that possible? And is anyone so kind to post me some VBA example code?
I'd like to change a numeric field into a text one but I'd like to
create an automatic procedure to do this..Maybe I can do it via SQL
query but I don't know if ALTER TABLE or something similar is supported
in Access.
Thanks a lot in advance to everyone.

Giuseppe
Nov 13 '05 #1
6 18175
ALTER TABLE is supported in JET 4 (Access 2000 and later), and is the
simplest way to alter a field type or size.

This example converts a field to Text type, 100 characters in size:
strSql = "ALTER TABLE MyTable ALTER COLUMN MyField TEXT(100);"

Execute the query statement under DAO like this:
dbEngine(0)(0).Execute strSql, dbFailOnError
or under ADO like this:
CurrentProject.Connection.Execute strSql

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Giuseppe Chielli" <gi******@NOSPAMlibero.it> wrote in message
news:d5**********@balena.cs.interbusiness.it...
Hi to everyone! I'm new in this NG. I'm posting this message just for
learning how can I modify the type of a field in a table via VBA code.
Is that possible? And is anyone so kind to post me some VBA example code?
I'd like to change a numeric field into a text one but I'd like to create
an automatic procedure to do this..Maybe I can do it via SQL query but I
don't know if ALTER TABLE or something similar is supported in Access.
Thanks a lot in advance to everyone.

Giuseppe

Nov 13 '05 #2
Allen Browne wrote:
ALTER TABLE is supported in JET 4 (Access 2000 and later), and is the
simplest way to alter a field type or size.

This example converts a field to Text type, 100 characters in size:
strSql = "ALTER TABLE MyTable ALTER COLUMN MyField TEXT(100);"

Thanks a lot. It works properly.But I have a new question now: how can I
insert a new field into a table before every other field (so as the
first field)?

Thanks in advance.

Giuseppe
Nov 13 '05 #3
Use DAO to set the OrdinalPosition of the Fields in the TableDef.

Of course, it may not matter, i.e. you can use a query as the source for
whatever needs the fields arranged in a certain way.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Giuseppe Chielli" <gi******@NOSPAMlibero.it> wrote in message
news:d5**********@carabinieri.cs.interbusiness.it. ..
Allen Browne wrote:
ALTER TABLE is supported in JET 4 (Access 2000 and later), and is the
simplest way to alter a field type or size.

This example converts a field to Text type, 100 characters in size:
strSql = "ALTER TABLE MyTable ALTER COLUMN MyField TEXT(100);"

Thanks a lot. It works properly.But I have a new question now: how can I
insert a new field into a table before every other field (so as the first
field)?

Thanks in advance.

Giuseppe

Nov 13 '05 #4
Allen Browne wrote:
Use DAO to set the OrdinalPosition of the Fields in the TableDef.

And what about using ADO? Can I modify the fields collection?
Nov 13 '05 #5
No, I don't see an ADO/ADOX property for doing this.

Of course, DAO is the library designed for Access.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Giuseppe Chielli" <gi******@NOSPAMlibero.it> wrote in message
news:d5**********@balena.cs.interbusiness.it...
Allen Browne wrote:
Use DAO to set the OrdinalPosition of the Fields in the TableDef.

And what about using ADO? Can I modify the fields collection?

Nov 13 '05 #6
Allen Browne wrote:
No, I don't see an ADO/ADOX property for doing this.

Of course, DAO is the library designed for Access.


Ok, I see. Thanks a lot from Italy! :)
Nov 13 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Chris McKeever | last post by:
I am trying to modify the Mailman Python code to stop mapping MIME-types and use the extension of the attachment instead. I am pretty much...
4
by: John | last post by:
I am using code provided by Mr. Steele that allows for my MDB to dynamically connect to remote SQL server databases. The code works fine as...
3
by: mrhicks | last post by:
Hello all, I have a question regarding efficeny and how to find the best approach when trying to find flag with in a structure of bit fields. I...
11
by: mesut demir | last post by:
Hi All, When I create fields (in files) I need assign a data type like char, varchar, money etc. I have some questions about the data types...
0
by: JDMils | last post by:
I am having trouble finding the AutoNumber field of my database with this code. The code is used to replicate a specific table, reproducing all...
4
by: lesperancer | last post by:
it looks like this will save many versions of a relationship window, but based on the fact that the same tables are displayed in the relationship...
4
by: Bob | last post by:
Hi all, I'm trying to import data, modify the data then insert it into a new table. The code below works fine for it but it takes a really long...
23
by: no1zson | last post by:
I have been adding buttons to my GUI to manipulate list data. I added a Delete button this morning in case I decide I no longer needed a particular...
14
by: Thurston Manson | last post by:
Suppose I'm using an implementation where an int is 16 bits. In the program below, what function is called in the first case, and what is called...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

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.