473,396 Members | 1,866 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.

Adding a Field using VB to an existing table.

Hello All,
I have these tables (lets call it ‘EmpCalls', ‘EmpOrders', and
‘Stats') that each contain the list of EmployeeIDs, I want to be able
to create a Module in which I could call in my VB form (by clicking
and command button)that will add a column (field) to each table and
label it with the current date that is specified in my form. Does
anyone know how I can go about doing this?
Any suggestion will be greatly appreciated.
Nov 12 '05 #1
11 14370
You could use DoCmd.RunSQL (or the DAO equivalent) to run an ALTER TABLE
statement which adds the field. Look up the syntax in Access help.

I'm curious though, why would you want to do this? I feel scary database
design in the offing...

"Bobbak" <bo****@ottawa.com> wrote in message
news:64**************************@posting.google.c om...
Hello All,
I have these tables (lets call it 'EmpCalls', 'EmpOrders', and
'Stats') that each contain the list of EmployeeIDs, I want to be able
to create a Module in which I could call in my VB form (by clicking
and command button)that will add a column (field) to each table and
label it with the current date that is specified in my form. Does
anyone know how I can go about doing this?
Any suggestion will be greatly appreciated.

Nov 12 '05 #2
Bobbak wrote:
I have these tables (lets call it ‘EmpCalls', ‘EmpOrders', and
‘Stats') that each contain the list of EmployeeIDs, I want to be able
to create a Module in which I could call in my VB form (by clicking
and command button)that will add a column (field) to each table and
label it with the current date that is specified in my form. Does
anyone know how I can go about doing this?


Your question is only the tip of the iceburg of problems
you're going to run into. There is a limit of 255 fields in
a table so this approach will eventually crump out on you.
It will also create all kinds of problems if you ever want
to have a report with totals or other cumulative results.
Having this kind of table is often called "committing
spreadsheet" on your database.

You should normalize your table by using a row for each
date/employee instead of adding a column for each date. A
good rule for designing tables is to remember that columns
are very expensive, but rows are almost free.

--
Marsh
MVP [MS Access]
Nov 12 '05 #3
Marshall Barton <ma*********@wowway.com> wrote in message news:<rt********************************@4ax.com>. ..
Bobbak wrote:
I have these tables (lets call it ?EmpCalls', ?EmpOrders', and
?Stats') that each contain the list of EmployeeIDs, I want to be able
to create a Module in which I could call in my VB form (by clicking
and command button)that will add a column (field) to each table and
label it with the current date that is specified in my form. Does
anyone know how I can go about doing this?


Your question is only the tip of the iceburg of problems
you're going to run into. There is a limit of 255 fields in
a table so this approach will eventually crump out on you.
It will also create all kinds of problems if you ever want
to have a report with totals or other cumulative results.
Having this kind of table is often called "committing
spreadsheet" on your database.

You should normalize your table by using a row for each
date/employee instead of adding a column for each date. A
good rule for designing tables is to remember that columns
are very expensive, but rows are almost free.


Well the database file itself will only contain data for one month at
a time, so the 255 field limit is not an issue.
The reason for me to have the code to add a column instead of adding
the columns manually when designing the table is to save myself some
time every month from re-creating the tables.
But thanks again for your suggestion, if you have any other ideas on
how i can achieve this, I'd very much like to know.
Nov 12 '05 #4
What are you planning to do when your boss wants a comparison of the last 2
months.

"Bobbak" <bo****@ottawa.com> wrote in message
news:64**************************@posting.google.c om...
Marshall Barton <ma*********@wowway.com> wrote in message

news:<rt********************************@4ax.com>. ..
Bobbak wrote:
I have these tables (lets call it ?EmpCalls', ?EmpOrders', and
?Stats') that each contain the list of EmployeeIDs, I want to be able
to create a Module in which I could call in my VB form (by clicking
and command button)that will add a column (field) to each table and
label it with the current date that is specified in my form. Does
anyone know how I can go about doing this?


Your question is only the tip of the iceburg of problems
you're going to run into. There is a limit of 255 fields in
a table so this approach will eventually crump out on you.
It will also create all kinds of problems if you ever want
to have a report with totals or other cumulative results.
Having this kind of table is often called "committing
spreadsheet" on your database.

You should normalize your table by using a row for each
date/employee instead of adding a column for each date. A
good rule for designing tables is to remember that columns
are very expensive, but rows are almost free.


Well the database file itself will only contain data for one month at
a time, so the 255 field limit is not an issue.
The reason for me to have the code to add a column instead of adding
the columns manually when designing the table is to save myself some
time every month from re-creating the tables.
But thanks again for your suggestion, if you have any other ideas on
how i can achieve this, I'd very much like to know.

Nov 12 '05 #5
"Bobbak" wrote
Marshall Barton <ma*********@wowway.com> wrote in message news:<rt********************************@4ax.com>. ..
Bobbak wrote:
I have these tables (lets call it ?EmpCalls', ?EmpOrders', and
?Stats') that each contain the list of EmployeeIDs, I want to be able
to create a Module in which I could call in my VB form (by clicking
and command button)that will add a column (field) to each table and
label it with the current date that is specified in my form. Does
anyone know how I can go about doing this?


Your question is only the tip of the iceburg of problems
you're going to run into. There is a limit of 255 fields in
a table so this approach will eventually crump out on you.
It will also create all kinds of problems if you ever want
to have a report with totals or other cumulative results.
Having this kind of table is often called "committing
spreadsheet" on your database.

You should normalize your table by using a row for each
date/employee instead of adding a column for each date. A
good rule for designing tables is to remember that columns
are very expensive, but rows are almost free.


Well the database file itself will only contain data for one month at
a time, so the 255 field limit is not an issue.
The reason for me to have the code to add a column instead of adding
the columns manually when designing the table is to save myself some
time every month from re-creating the tables.
But thanks again for your suggestion, if you have any other ideas on
how i can achieve this, I'd very much like to know.


Columns are added using SQL's ALTER TABLE, DAO's CreateField
or ADO's Fields.Append. However, your problem description
suggests this may not be the solution.

De-normalizing can be the thing to do - most often for boosting
performance in reporting systems. Tracking history (that's what
your after, or?) is hardly ever a good reason and de-normalizing
operational data is almost taboo.

Look again at Marshall's suggestion and consider crosstab queries for
lining up the dates. Why re-create tables or add columns at all?
Simply empty the tables each month, if you really must.
Nov 12 '05 #6
"paii, Ron" <pa**@packairinc.com> wrote in message news:<vp************@corp.supernews.com>...
What are you planning to do when your boss wants a comparison of the last 2
months.

That's not gonna happen, the purpose of this is to have a monthly
figure per employee, by day.

Now can we get back to my orginal question.
Nov 12 '05 #7
"Ben Eaton" <be************@hotmail.com> wrote in message news:<bn***********@news.wplus.net>...
You could use DoCmd.RunSQL (or the DAO equivalent) to run an ALTER TABLE
statement which adds the field. Look up the syntax in Access help.

I'm curious though, why would you want to do this? I feel scary database
design in the offing...

You have nothing to be scared of, this isn't your database that you
are doing this too.
Nov 12 '05 #8
You will may not get much help doing what you propose. Along with what
Marshall Barton stated, I think you will have table corruption problems is
you try to add fields to a active database. You cannot add fields to a table
while you are viewing it with a form.

If you add a date field to your detail records, it will be easy to use a
cross tab query to extract dates from any month. The Cross tab will have the
dates as column headings. You can then empty the tables every month,
although that will not be necessary.

"Bobbak" <bo****@ottawa.com> wrote in message
news:64**************************@posting.google.c om...
"paii, Ron" <pa**@packairinc.com> wrote in message

news:<vp************@corp.supernews.com>...
What are you planning to do when your boss wants a comparison of the last 2 months.

That's not gonna happen, the purpose of this is to have a monthly
figure per employee, by day.

Now can we get back to my orginal question.

Nov 12 '05 #9

"Bobbak" <bo****@ottawa.com> wrote in message
news:64**************************@posting.google.c om...
"Ben Eaton" <be************@hotmail.com> wrote in message

news:<bn***********@news.wplus.net>...
You could use DoCmd.RunSQL (or the DAO equivalent) to run an ALTER TABLE
statement which adds the field. Look up the syntax in Access help.

I'm curious though, why would you want to do this? I feel scary database design in the offing...

You have nothing to be scared of, this isn't your database that you
are doing this too.


We do get a bit scared and do have something to be scared of.
We might be hired after you leave and one person bad mouthing Access does
more harm than 1000 silent because they are happy people can overcome.

Mostly I suspect we are curious since writing code to add something that
will only be useful in a table after it has been created unless you plan on
writing a lot more code is a curious thing.


Nov 12 '05 #10
Might be a more useful table if it were something like

CREATE TABLE SomeTable(
EmployeeID Long,
ActionDate Date,
Amount Currency,
PRIMARY KEY (EmployeeID, ActionDate));

Sorry for the bad SQL, but you get the idea. This way, as long as you
add only one value per employee per day, who cares if you have a half
million records? You can filter, summarize, and all that good
stuff... PITA if you keep adding columns all over the place...
Nov 12 '05 #11
>> Bobbak wrote:
> I have these tables (lets call it ?EmpCalls', ?EmpOrders', and
>?Stats') that each contain the list of EmployeeIDs, I want to be able
>to create a Module in which I could call in my VB form (by clicking
>and command button)that will add a column (field) to each table and
>label it with the current date that is specified in my form. Does
>anyone know how I can go about doing this?

Marshall Barton wrote
Your question is only the tip of the iceburg of problems
you're going to run into. There is a limit of 255 fields in
a table so this approach will eventually crump out on you.
It will also create all kinds of problems if you ever want
to have a report with totals or other cumulative results.
Having this kind of table is often called "committing
spreadsheet" on your database.

You should normalize your table by using a row for each
date/employee instead of adding a column for each date. A
good rule for designing tables is to remember that columns
are very expensive, but rows are almost free.

Bobbak wrote:Well the database file itself will only contain data for one month at
a time, so the 255 field limit is not an issue.
The reason for me to have the code to add a column instead of adding
the columns manually when designing the table is to save myself some
time every month from re-creating the tables.
But thanks again for your suggestion, if you have any other ideas on
how i can achieve this, I'd very much like to know.

I'm pretty sure I understand what you're trying to do. It's
just that I think you are creating a host of problems for
the future. What you described sound like a one to many
relationship from the table to the dates and whatever data
you place in the date columns.

Oh well, it's your db and you can ignore advice if you want
to. I think an DAO air code outline of a routine to add a
column for the date in a text box on a form might look like:

Dim db As Database
Dim tdf as TableDef
Dim fld As Field

Set db = CurrentDb()
Set tdf = db.TableDefs("thetable")
Set fld = tdf.CreateField(Format(Forms!theform.thetextbox, _
dbInteger)
tdf.Fields.Append fld

Set fld = Nothing
Set tdf = Nothing
Set db = Nothing

--
Marsh
MVP [MS Access]
Nov 12 '05 #12

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

Similar topics

3
by: Claudio Lapidus | last post by:
Hello Now perhaps this is a bit dumb, but... I just populated a new table via \copy. After that, I realize that perhaps is a good thing to have a row identifier in it, so I try clapidus=>...
2
by: Gail Zacharias | last post by:
I am investigating the possibility of using pgsql as the database in an application. I have some unusual requirements that I'd like to ask you all about. I apologize in advance if my terminology is...
1
by: Tony D. | last post by:
I could really use some help with a problem I am having. I am trying to add a new field to an existing form that combines two tables into one form. In this same databse I have another form that...
2
by: Randy A. Bohannon | last post by:
This is probably a simple thing to do, but I can't find how in the help files or the manual I have. I'm using Access 2000. I have three tables joined by a common field, and I'm using one form...
3
by: GL | last post by:
Hi, Is there a way to add a field to an existing table using a query of some sort (without needing to manually add a field to the table). I know how to do it with a make table query, but I have...
12
by: Art | last post by:
Hi everyone I was hoping someone might be able to help me with this. I'm just starting to try to work with MS Access tables through VB.net. In Access I can take an existing table and add a new...
6
by: Rudy | last post by:
Hi all, I know this is easy, just can't seem to get it. I have a windows form, and a text box, with a value already in it. I need to add that value to a table. It's just one value, so the entire...
3
by: Microsoft_Public | last post by:
All I'm getting is <null>...... I have a legacy input form that I must maintain for a few more months until the balance of the site can be converted to .Net. I need the one database field to...
1
by: Dixie | last post by:
I want to append a number of records onto an existing table. Each record will have an ID number (it is not an autonumber as it is too variable). It is currently set as an integer field. I want...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
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.