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

Macro Insert New Field (Date datatype)

Greetings!

I currently have a table named 2008-01-30. I would like to insert a new field, and I would like that field to be in a Date format and have it populated with the table name. I'll be using this macro on multiple tables.

I don't know how to pull from the table name, so I thought I'd try just getting it to insert the column/field and a date, hence the value 3/14/08. It doesn't work.. I just get a lot of runtime errors about syntax, but it looks right to me?

Here's what I have:
Expand|Select|Wrap|Line Numbers
  1.  
  2. DoCmd.RunSQL "ALTER TABLE 2008-01-30 ADD COLUMN (Date)"
  3. DoCmd.RunSQL "INSERT INTO 2008-01-30 ([Date]) VALUES (#03/14/2008#)"
As you can see, I'm trying to do this using SQL in VBA, but I'm open to other suggestions, as I have no idea what I'm doing here!

Also, I'm using XP Pro and Access 2002, FYI.

Thanks in advance! I really appreciate it!!
May 20 '08 #1
8 4594
FishVal
2,653 Expert 2GB
Add date field to a table [2008-01-30]?
Would you like Database Normalization and Table structures article ?

Kind regards,
Fish
May 20 '08 #2
Hi Fish,

Thank you for replying! Unfortunately, I don't think the article you provided will help me. I need help with writing the macro, including the VBA and, if necessary, SQL.

Any VBA pros out there? :)


Add date field to a table [2008-01-30]?
Would you like Database Normalization and Table structures article ?

Kind regards,
Fish
May 20 '08 #3
FishVal
2,653 Expert 2GB
Ok. It will be more clear with an example. Would you describe what your database is expected to do and what you've done already to achieve this?

Kind regards,
Fish
May 20 '08 #4
Ok, no problem. I have two fields right now, employee name and employee number. I have many tables, each named with a date (example: 2008-01-30). I want to write a macro that will insert a new field in each table. This field will be for the date, and pull the date from the table name. As I noted in my first post, here is what I have tried:
Expand|Select|Wrap|Line Numbers
  1.       DoCmd.RunSQL "ALTER TABLE 2008-01-30 ADD COLUMN (Date)"
  2.       DoCmd.RunSQL "INSERT INTO 2008-01-30 ([Date]) VALUES (#03/14/2008#)"
...but it doesn't work. Although it looks like it should to me. What am I missing?

As I also said in my first post, I don't know how to pull the date from the table name, so I was trying to get it to put in any date, so I used 3/14/08 as my test.

Thanks in advance!
May 21 '08 #5
NeoPa
32,556 Expert Mod 16PB
It's a shame you didn't pick up on the main point that was being made (politely) :
"Don't do it this way!
This type of database design is utterly wrong and one of the side-effects of this is that you will create problems for yourself."

The fact that this question is even posted is an illustration of how this design has already caused you problems you shouldn't need to have to worry about.
May 21 '08 #6
I'm sorry, but I'm very new to this and am just trying to pick this up. I'm open to all suggestions.


It's a shame you didn't pick up on the main point that was being made (politely) :
"Don't do it this way!
This type of database design is utterly wrong and one of the side-effects of this is that you will create problems for yourself."

The fact that this question is even posted is an illustration of how this design has already caused you problems you shouldn't need to have to worry about.
May 21 '08 #7
NeoPa
32,556 Expert Mod 16PB
Bearing in mind we don't know very much about your database as a whole and the reasons for it, the best advice we can really give is to look at the article linked earlier about normalisation.

Microsoft have tried to sell the story that anyone can pick up Access and run with it, regardless of how little understanding they have of database concepts and structure. We have living proof in many, many threads that this is simply not the case. Unless the overview of the project is well structured (and typically conforms to the "rules" laid out in the normalisation article) then it will get progressively more difficult to understand and develop in.

Sometimes, helping someone directly with a problem when you know that they're going about things the wrong way, just leads them further into the mire before they eventually realise they need to stop and start again.

You need to ask yourself :
What exactly am I trying to achieve?
How do I envisage getting there?
Will a database system like Access fit into the plan neatly?

It is beyond the practical scope of a forum such as this, but maybe consider some introductory course on Access too - one which includes the database fundamentals. Coding is easy to pick up and is not what I'm banging on about anyway. It's the structure issues which are the tough one for those new to it to get to grips with.

PS. I hope you understand this is not about criticising you. I'm trying to be constructive.
May 21 '08 #8
I appreciate your suggestions and I'll look into this further. Thanks
May 21 '08 #9

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

Similar topics

2
by: Tavish Muldoon | last post by:
What a pain trying to insert data into a table from a stored proc. My webform asks for 16 pieces of data - which then gets written to the database. I found this easier than the crap below...
1
by: ms | last post by:
I am running an insert statement from a dbf file and there is one record causing the insert to fail. A msg. is returned stating it is due to an invalid datatype. There are 2 text fields, 2...
3
by: La di da Limey | last post by:
Hi, I have a field in a database called "Timestamp" which has the date and time of an event, for example: "01/02/2002 09:07:59" The format is MM/DD/YYYY HH:MM:SS I want to chop the field...
3
by: os2 | last post by:
hi i have an insertion problem with my rtu table datatype for date1 field is: datetime i try to insert local date to the database (mysql) source code struct tm *date;
2
by: WØCBF | last post by:
I am trying to copy the information from a form into a table. I have tried running the sql code from a macro by using the command : This works and writes the work 'test' into the field name...
3
by: Miro | last post by:
Something weird I have run into when trying to add a boolean field to an Access table by code. -Just wondering if anyone else has run into this. ( vb.net 2005 express ) If I add any other...
6
by: rn5a | last post by:
During registration, users are supposed to enter the following details: First Name, Last Name, EMail, UserName, Password, Confirm Password, Address, City, State, Country, Zip & Phone Number. I am...
0
by: =?Utf-8?B?TGV0emRvXzF0?= | last post by:
I'd like to create a Macro that will sort some raw data, apprx 20k lines, remove some lines based upon a condition in a certain column. Then copy this data into a new spreadsheet and sort the ...
3
by: Kunal Desale | last post by:
Hi, How to insert/update data in foxpro table field having datatype MEMO using Linked Server? I have written sql insert queries in which i have used linked server to insert data into foxpro...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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: 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
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,...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.