Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automatically fill in field based on number of reiterations

Status
Not open for further replies.

AKBirdie

Programmer
Oct 7, 2008
2
US
I am trying to create a field (either in my original table or in a query) that automatically fills in the visit number for each individual, so when an individual makes a subsequent visit, the visit# will automatically fill in.

ie:

IND VISIT#
a 1
a 2
a 3
b 1
b 2
c 1

...if INDIVIDUAL "a" makes another visit, VISIT# will be 4.

IND VISIT#
a 1
a 2
a 3
a 4
b 1
b 2
c 1

Thanks!
 
Why not normalize your data and list each individual only 1 time in the table? Then, you can update the visit number simply by adding 1 to the current value at each subsequent visit.


Randy
 
There are a number of other fields associated with this individual other than visit number that complicates the db. It has to be this way and can't be normalized.

Any ideas sin normailzation?
 
Just looking at what you wrote if you did you could create a function that will create a simple recordset.

set rs = "Select Visit From tablename where Individual = 'a'"

then set the function return equal to rs.recordcount + 1

That should accomplish what you are looking for.
 
or do the same as the above with using "Select MAX Visit from tablename where individual = 'a'" and then increment that by 1.
 
How are ya AKBirdie . . .

I agree with [blue]randy700[/blue], but since we don't know your table structure, how about using [blue]DMax[/blue] to get the max value for an individual and simply add 1?
Code:
[blue]Me!Visit# = DMax("[Visit#]", "TableName", "[Ind] = '" & Me![Ind] & "'")[/blue]
[blue]Your Thouhts? . . .[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top