Answered by:
Maximum number of Records

Question
-
Hello experts,
How would I set the maximum number of records in a table. Lets say I only want to allow 100 records and anything greater then 100
messagebox(" you have exceeded the maximum number records")
Friday, October 12, 2012 4:34 AM
Answers
-
@Lakshmi
That's a slow and inefficient way to do it. Also, it is not good to select a specific work area number. SELECT 0 will always select the next unused work area or you can USE TheTable IN 0.
@mikelvfp
When you save, just check RECCOUNT("Alias"). That will give you the total number of records for that table, including deleted records.
Craig Berntson
MCSD, Visual C# MVP
INETA Community Speaker
www.craigberntson.com- Marked as answer by mikelvfp Friday, October 12, 2012 5:17 PM
Friday, October 12, 2012 1:42 PM
All replies
-
If the table belongs to a database, you should be able to implement this logic in a trigger.
For every expert, there is an equal and opposite expert. - Becker's Law
My blog- Proposed as answer by Tom BorgmannEditor Friday, October 12, 2012 8:18 AM
Friday, October 12, 2012 4:36 AM -
hi
if you are writing a program. then in the main program.
select 1
use master && name of the file
count to x
if x > 100
messagebox("you have exceeded the maximum number of records",0)
endif
Lakshmi
Friday, October 12, 2012 4:53 AM -
Hi Lakshmi,
by using your approach, as long as the User never closes the app any number of records could be inserted. Therefore, Naomi's suggestion of using an (->insert) trigger is the best solution.
Doing something like that in the app itself would mean, to run a db table count every time and everywhere a record shall be inserted into the table. Depending on the complexity of the app this might happen at many places. Using a trigger reduces this to one single place: The table itself.
Gruss / Best regards
-Tom
Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible,
you are, by definition, not smart enough to debug it. 010101100100011001010000011110000101001001101111011000110110101101110011Friday, October 12, 2012 8:25 AMAnswerer -
@Lakshmi
That's a slow and inefficient way to do it. Also, it is not good to select a specific work area number. SELECT 0 will always select the next unused work area or you can USE TheTable IN 0.
@mikelvfp
When you save, just check RECCOUNT("Alias"). That will give you the total number of records for that table, including deleted records.
Craig Berntson
MCSD, Visual C# MVP
INETA Community Speaker
www.craigberntson.com- Marked as answer by mikelvfp Friday, October 12, 2012 5:17 PM
Friday, October 12, 2012 1:42 PM -
Hi Craig,
I followed your suggestion and it works, however Id just like to make sure this is fine
select invoichdr if reccount() > 100 messagebox("You have exceeded maximum number of records") else thisform.save() endif
Friday, October 12, 2012 3:34 PM -
If there is only way to insert rows in that table and you want to include deleted rows into your calculations, then it's OK.
For every expert, there is an equal and opposite expert. - Becker's Law
My blogFriday, October 12, 2012 4:11 PM -
hmm, i never saw that coming. I guess its fine...
but if I didnt want to count for deleted rows, would i use your suggestion Naomi? or is there a workaround?Friday, October 12, 2012 4:22 PM -
If you don't want to count deleted rows, instead of using RECCOUNT() you need to do
COUNT to lnCurRows
assuming that you're using SET DELETED ON setting.
For every expert, there is an equal and opposite expert. - Becker's Law
My blogFriday, October 12, 2012 5:04 PM -
thank you Naomi, and thank you Craig...problem solvedFriday, October 12, 2012 5:16 PM