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

MS Access Question for Access Gurus

I have one table called Album
another table called Song

One Album has many songs

I created an Album form that contains a Song Subform.

in the Song table I have a field id which is the primary key, and
another field called index

The song index is a number that represents the song number on the record.

For example on the Beatle's Album: Abbey Road the song indices are as
follows:

Track Listings
1. Come Together
2. Something
3. Maxwell's Silver Hammer
4. Oh! Darling
5. Octopus's Garden
6. I Want You (She's So Heavy)
7. Here Comes the Sun
8. Because
9. You Never Give Me Your Money
10. Sun King
11. Mean Mr. Mustard
12. Polythene Pam
13. She Came in Through the Bathroom Window
14. Golden Slumbers
15. Carry That Weight
16. End
17. Her Majesty

My question is.....on the song subform how can I get the song index to
automatically have the index inserted based on the number of tracks
already entered. In other words a running count?

For your information, here are my tables

Table: Album
Primary Key: id (number)
name (text)

Table: Song
Primary Key: id (number)
name (text)
index (number)
albumID (foreign key)

Relationship is One Album to Many Songs with Referential Integrity.

I really appreciate your help.
Nov 13 '05 #1
8 1645

"Elliot W. Scott" <no****@nospam.com> wrote in message news:mu********************@comcast.com...
I have one table called Album
another table called Song

One Album has many songs

I created an Album form that contains a Song Subform.

in the Song table I have a field id which is the primary key, and another field called index

The song index is a number that represents the song number on the record.

For example on the Beatle's Album: Abbey Road the song indices are as follows:

Track Listings
1. Come Together 2. Something 3. Maxwell's Silver Hammer 4. Oh! Darling 5. Octopus's Garden 6. I Want You (She's So
Heavy) 7. Here Comes the Sun 8. Because 9. You Never Give Me Your Money 10. Sun King 11. Mean Mr. Mustard 12.
Polythene Pam 13. She Came in Through the Bathroom Window 14. Golden Slumbers 15. Carry That Weight 16. End 17. Her
Majesty
My question is.....on the song subform how can I get the song index to automatically have the index inserted based on the number
of tracks already entered. In other words a running count?

For your information, here are my tables

Table: Album
Primary Key: id (number)
name (text)

Table: Song
Primary Key: id (number)
name (text)
index (number)
albumID (foreign key)

Relationship is One Album to Many Songs with Referential Integrity.

I really appreciate your help.


the short answer, I think, is that you should use this function as the default value for the ID (index) number:

dmax("[index]","[song]", "[albumID]=" & forms!myform!albumID)+1

This means: the maximum value for index in the song table where the albumID is equal to the album ID that is currently shown in
myform.

I am not sure what you should have instead of myform, but someone else or yourself may figure this out.

Nicolaas
Nov 13 '05 #2
windandwaves wrote:
dmax("[index]","[song]", "[albumID]=" & forms!myform!albumID)+1


Nz(dmax("[index]","[song]", "[albumID]=" & forms!myform!albumID),0)+1
As the first one will return a null.
or (not sure but try)
Nz(dmax("[index]","[song]", "[albumID]=" & form.Parent!albumID),0)+1
would be portable to another form.

--
This sig left intentionally blank
Nov 13 '05 #3
Trevor Best wrote:
windandwaves wrote:
dmax("[index]","[song]", "[albumID]=" & forms!myform!albumID)+1

Nz(dmax("[index]","[song]", "[albumID]=" & forms!myform!albumID),0)+1
As the first one will return a null.
or (not sure but try)
Nz(dmax("[index]","[song]", "[albumID]=" & form.Parent!albumID),0)+1
would be portable to another form.

I think something is wrong I get an #error
I don't know what this is.
\/
Nz(dmax("[index]","[song]", "[albumID]=" & form.Parent!albumID),0)+1
Is [song] my Song table? or should it be the song id?
Nov 13 '05 #4
Trevor Best wrote:
windandwaves wrote:
dmax("[index]","[song]", "[albumID]=" & forms!myform!albumID)+1

Nz(dmax("[index]","[song]", "[albumID]=" & forms!myform!albumID),0)+1
As the first one will return a null.
or (not sure but try)
Nz(dmax("[index]","[song]", "[albumID]=" & form.Parent!albumID),0)+1
would be portable to another form.

I think something is wrong I get an #error
I don't know what this is.
\/
Nz(dmax("[index]","[song]", "[albumID]=" & form.Parent!albumID),0)+1
Is [song] my Song table? or should it be the song id?
Nov 13 '05 #5
Trevor Best wrote:
windandwaves wrote:
dmax("[index]","[song]", "[albumID]=" & forms!myform!albumID)+1

Nz(dmax("[index]","[song]", "[albumID]=" & forms!myform!albumID),0)+1
As the first one will return a null.
or (not sure but try)
Nz(dmax("[index]","[song]", "[albumID]=" & form.Parent!albumID),0)+1
would be portable to another form.

I think something is wrong I get an #error
I don't know what this is.
\/
Nz(dmax("[index]","[song]", "[albumID]=" & form.Parent!albumID),0)+1
Is [song] my Song table? or should it be the song id?
Nov 13 '05 #6
Elliot W. Scott wrote:
Trevor Best wrote:
windandwaves wrote:
dmax("[index]","[song]", "[albumID]=" & forms!myform!albumID)+1


Nz(dmax("[index]","[song]", "[albumID]=" & forms!myform!albumID),0)+1
As the first one will return a null.
or (not sure but try)
Nz(dmax("[index]","[song]", "[albumID]=" & form.Parent!albumID),0)+1
would be portable to another form.

I think something is wrong I get an #error
I don't know what this is.
\/
Nz(dmax("[index]","[song]", "[albumID]=" & form.Parent!albumID),0)+1
Is [song] my Song table? or should it be the song id?


dmax(fieldname,tablename,criteria)
Yes, that should be your song table.

Also, where is this DMax being executed from?

Have you tried the:
Nz(dmax("[index]","[song]", "[albumID]=" & forms!myform!albumID),0)+1
approach?

If addressing the form from code, you should use Me instead of Form, e.g.
Nz(dmax("[index]","[song]", "[albumID]=" & Me.Parent!albumID),0)+1

Alternatively you should put this DMax into the DefaultValue property,
don't put in the ControlSource property, if you do it needs a "=" before
it and it won't save it anywhere.

--
This sig left intentionally blank
Nov 13 '05 #7
Trevor Best wrote:
Elliot W. Scott wrote:
Trevor Best wrote:
windandwaves wrote:

dmax("[index]","[song]", "[albumID]=" & forms!myform!albumID)+1


Nz(dmax("[index]","[song]", "[albumID]=" & forms!myform!albumID),0)+1
As the first one will return a null.
or (not sure but try)
Nz(dmax("[index]","[song]", "[albumID]=" & form.Parent!albumID),0)+1
would be portable to another form.

I think something is wrong I get an #error
I don't know what this is.
\/
Nz(dmax("[index]","[song]", "[albumID]=" & form.Parent!albumID),0)+1
Is [song] my Song table? or should it be the song id?

dmax(fieldname,tablename,criteria)
Yes, that should be your song table.

Also, where is this DMax being executed from?

Have you tried the:
Nz(dmax("[index]","[song]", "[albumID]=" & forms!myform!albumID),0)+1
approach?

If addressing the form from code, you should use Me instead of Form, e.g.
Nz(dmax("[index]","[song]", "[albumID]=" & Me.Parent!albumID),0)+1

Alternatively you should put this DMax into the DefaultValue property,
don't put in the ControlSource property, if you do it needs a "=" before
it and it won't save it anywhere.


Thanks. I had to do the it as follows:
=Nz(DMax("[index]","[Song]","[albumID]=" &[Forms]![AlbumForm]![id]),0)+1

but it still doesn't work, it does it in a weird pattern...

It does this for my index:
1
1
2
2
3
3
4
4
5
5
6
6
.....
I think it does this because the new record is created before I am done
with the one I am currently creating. :(

Nov 13 '05 #8
Elliot W. Scott wrote:
Trevor Best wrote:
Elliot W. Scott wrote:
Trevor Best wrote:

windandwaves wrote:

> dmax("[index]","[song]", "[albumID]=" & forms!myform!albumID)+1

Nz(dmax("[index]","[song]", "[albumID]=" & forms!myform!albumID),0)+1
As the first one will return a null.
or (not sure but try)
Nz(dmax("[index]","[song]", "[albumID]=" & form.Parent!albumID),0)+1
would be portable to another form.

I think something is wrong I get an #error
I don't know what this is.
\/
Nz(dmax("[index]","[song]", "[albumID]=" & form.Parent!albumID),0)+1
Is [song] my Song table? or should it be the song id?


dmax(fieldname,tablename,criteria)
Yes, that should be your song table.

Also, where is this DMax being executed from?

Have you tried the:
Nz(dmax("[index]","[song]", "[albumID]=" & forms!myform!albumID),0)+1
approach?

If addressing the form from code, you should use Me instead of Form, e.g.
Nz(dmax("[index]","[song]", "[albumID]=" & Me.Parent!albumID),0)+1

Alternatively you should put this DMax into the DefaultValue property,
don't put in the ControlSource property, if you do it needs a "="
before it and it won't save it anywhere.


Thanks. I had to do the it as follows:
=Nz(DMax("[index]","[Song]","[albumID]=" &[Forms]![AlbumForm]![id]),0)+1

but it still doesn't work, it does it in a weird pattern...

It does this for my index:
1
1
2
2
3
3
4
4
5
5
6
6
....
I think it does this because the new record is created before I am done
with the one I am currently creating. :(


Try requerying the index textbox in Form_BeforeInsert()

--
This sig left intentionally blank
Nov 13 '05 #9

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

Similar topics

6
by: John Sheppard | last post by:
Hi there, Does anyone know if there exists an irc channel where all the Access gurus hang out? Thanks! John Sheppard
2
by: bala | last post by:
hi access gurus would appreciate if u can give me pointers regarding conversion of ms access 97 application to ms access 2000, like what are the problems to be expected and how to handle it. ...
13
by: BigDaDDY | last post by:
Um yeah....In case you haven't figured it out, Microsoft sucks. I'm going to be kicked back in my chair eating popcorn and watching football 10 years from now, while all you clowns are scrambling...
0
by: Steve | last post by:
Greetings, I'm having problems with the use of an Access 2003 Add-In on Windows XP Pro. Administrative-level users have no problems running the Add-In, but those users with restricted rights on...
11
by: WindAndWaves | last post by:
Hi Gurus I have recently discovered references in the VB section of MS Access, however, when choosing references, I noticed that there are more than who knows how many options. How and/or where...
4
by: Shahzad | last post by:
dear respected gurus, I would like to knew how to apply append,insert query for a self table where no primary keys issues. i do have problem say there are 5 rows of single record, this is data...
2
by: plau011 | last post by:
Hello Access gurus, I am curious as to why you can't open an Access 2003 Db with Access 2000. We have a Visual Basic application which is using DAO 3.6 to connect to the Access database. It IS...
70
by: lgbjr | last post by:
Hello All, I've been developing a VB.NET app that requires the use of a DB. Up to now, I've been using Access. It's a bit slow, but everything works. I'm at a point now where I need to decide if...
1
by: bala | last post by:
Hi Access Gurus The MS Access DB (MS Access 2002 Database) which is currently serving as the backend Database to MS Access (MS Access 2002/XP) frontend needs to be converted to Oracle 8i Backend...
9
by: prakashwadhwani | last post by:
Hi !! I'm about to develop a new project for a client. Should I go about it in Access 2003 or 2007 ? Purchasing it either for me or for my client is not a major consideration here ... what I'd...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.