473,396 Members | 2,010 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.

Help with adding a calculated field to a table?

First of all, I want to thank everyone who posts messages in this
group. I am very new to VB and developing full-blown database apps,
and I have learned a great deal by reading these posts, so I am very
grateful.

I have a problem that I have been working on, and I was wondering if
anyone had a simple solution.

I have a table of data similar to the example shown below:

TextField NumberField
Txt1 1
Txt2 2
Txt3 3
Txt4 1
Txt5 2
Txt6 3
Txt7 4
Txt8 1
Txt9 2
etc.

I would like to add a calculated field to the table that starts with
the number 1 for the first series of data 1-3, ratchets up to the
number 2 for 1-4, and the to the number 3 for the third set of numbers,
so my final table would be:

TextField NumberField Calculatedfield
Txt1 1 1
Txt2 2 1
Txt3 3 1
Txt4 1 2
Txt5 2 2
Txt6 3 2
Txt7 4 2
Txt8 1 3
Txt9 2 3
etc.

My actual dataset in the number field would be sequences of numbers
starting with 1 and going up to either 6, 7, or 8.

Any ideas? Thanks in advance for the help.

May 21 '06 #1
4 2424
"bpneary1" <bp******@yahoo.com> wrote in
news:11**********************@i39g2000cwa.googlegr oups.com:
First of all, I want to thank everyone who posts messages in
this group. I am very new to VB and developing full-blown
database apps, and I have learned a great deal by reading
these posts, so I am very grateful.

I have a problem that I have been working on, and I was
wondering if anyone had a simple solution.

I have a table of data similar to the example shown below:

TextField NumberField
Txt1 1
Txt2 2
Txt3 3
Txt4 1
Txt5 2
Txt6 3
Txt7 4
Txt8 1
Txt9 2
etc.

I would like to add a calculated field to the table that
starts with the number 1 for the first series of data 1-3,
ratchets up to the number 2 for 1-4, and the to the number 3
for the third set of numbers, so my final table would be:

TextField NumberField Calculatedfield
Txt1 1 1
Txt2 2 1
Txt3 3 1
Txt4 1 2
Txt5 2 2
Txt6 3 2
Txt7 4 2
Txt8 1 3
Txt9 2 3
etc.

My actual dataset in the number field would be sequences of
numbers starting with 1 and going up to either 6, 7, or 8.

Any ideas? Thanks in advance for the help.

It's a little late to start thinking about this after the data
is in hte table, because no database will guarantee the order of
records that will be returned from a query.

Is there any other field that's common to all rows in any one
set? you could use that as a starter. add the numbers there,
then go back and insert the numbers in between

You could also open the recordset, and using a do loop, proceed
through the table, incrementing a counter when NumberField = 1
dim rs as recordset
dim lGroupCounter as long
SET rs = currentdb.openrecordset("tablename")

Do Until rs.EOF
if rs!Numberfield then lGroupCounter = lGroupCounter +1
rs.edit
rs!Calculatedfield = lGroupCounter
rs.update
rs.movenext
loop
rs.close
SET rs = nothing

--
Bob Quintal

PA is y I've altered my email address.
May 21 '06 #2
Bob,

Thanks for the help. I failed to mention that immediately prior to
running the code that you included in your post, I am importing the
data from a text file, therefore it comes into the database in the
proper order, and I immediated add that calculated field. I just tried
it out and it works great. Thanks again.

May 22 '06 #3

"bpneary1" <bp******@yahoo.com> wrote in message
news:11**********************@j73g2000cwa.googlegr oups.com...
Bob,

Thanks for the help. I failed to mention that immediately prior to
running the code that you included in your post, I am importing the
data from a text file, therefore it comes into the database in the
proper order, and I immediated add that calculated field. I just tried
it out and it works great. Thanks again.


The point to be made is: records in relational DB tables is, by definition,
_un_ordered. So, unless there is a key or indexed field(s) to ensure the
order of the records when they are retrieved, you can't _count_ on the
calculated field.

Relational tables are not sequential data sets, and that appears to be the
assumption for the calculation you desire.

Larry Linson
Microsoft Access MVP

May 22 '06 #4
"Larry Linson" <bo*****@localhost.not> wrote in
news:JIccg.4067$oa3.3702@trnddc08:

"bpneary1" <bp******@yahoo.com> wrote in message
news:11**********************@j73g2000cwa.googlegr oups.com...
Bob,

Thanks for the help. I failed to mention that immediately
prior to running the code that you included in your post, I
am importing the data from a text file, therefore it comes
into the database in the proper order, and I immediated add
that calculated field. I just tried it out and it works
great. Thanks again.


The point to be made is: records in relational DB tables is,
by definition, _un_ordered. So, unless there is a key or
indexed field(s) to ensure the order of the records when they
are retrieved, you can't _count_ on the calculated field.

Relational tables are not sequential data sets, and that
appears to be the assumption for the calculation you desire.

Larry Linson
Microsoft Access MVP


About the only time I use an autonumber is when I encounter this
situation. I import to a temp table, that has an autonumber ID.
I then process the dataset and move the stuff to the permanent
table.

--
Bob Quintal

PA is y I've altered my email address.
May 22 '06 #5

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

Similar topics

15
by: Colin | last post by:
I have a query that calculates the selling price of products on customer orders. Selling prices are calculated based on the average cost of the items when purchased. As I make new purchases, the...
6
by: 6thirty | last post by:
Hi, I've created a stocktaking database using Access XP. This is indexed by two fields - part number and shelf location. I am currently inputting all the data via a form. When I have entered a...
9
by: Tony Williams | last post by:
I have two tables 1.tblmonth which holds two fields txtmonth and txtqtrlabel and 2. tblmain which holds a number of fields but in particular a field called txtqtrlabel2. The two tables are linked...
8
by: TORQUE | last post by:
Hi, I am having some trouble with recording a field on a form into my Table after formatting it to calculate several fields on the form. If i just put the amount in the field and have it linked...
10
by: 60325 | last post by:
This is the page where I collect the data in drop-down boxes with values of 1-10 and send it to a submitted page to do calculations. Example: Employee1 TeamScore(1-10) Employee2 ...
5
by: Henrik | last post by:
The problem is (using MS Access 2003) I am unable to retrieve long strings (255 chars) from calculated fields through a recordset. The data takes the trip in three phases: 1. A custom public...
1
by: Steve Harp | last post by:
Hi All, I'm not sure this can be done in a calculated field but here's what I need. I have a table that stores time off for employees (such as vacation, sick time, etc). An employee can take...
2
by: jcf378 | last post by:
hi all. I have a form which contains a calculated control ("days") that outputs the # of days between two dates (DateDiff command between the fields and ). However, when I click "Filter by...
6
by: ccsoupy22 | last post by:
For simplicity sake, here are the basics of the query I am stumped on... Type: Select query Name: ColorCells Below is a partial list of the "Cases" for the code (I did not think there was...
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
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:
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
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.