Discussion Locked

Access 97 Query

0 helpful
23 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I have a query with 2 fields. One is a Slip number, which is a number that should increment by one for each record.

Is there anyway to have access tell from one record to the next if the number goes up by more than one? ie. a Slip has been skipped.

These numbers are hand entered, because they relate to hard copies. It cannot be auto incrememnt.

Thx, Loyd

23 replies

by mslizny

You need another field, with an IIF function something like this:

IIF SlipNo. is not equal to previous record SlipNo. +1, Yes, No

This means that in this field if the SlipNo. is not equal to the previous record's SlipNo.=1, you would see the value No, otherwise it would be Yes.

You would want to be sure the SlipNo. field is truly a number field.

by shanghai sam

When do you want to do the check?
If you want to do the check after a user enters the number, then I would use a function to do the check at whatever point needed (ie. Close form, textbox_After_Update etc). Do a SELECT query in the function and ORDER BY slipNo, move the cursor to the last entered record and check the SlipNo value. If this value is not equal to the current slip number minus one, then raise the error. (All as follows:)
------------------------Start code example
Private Function Last_Slip_No As long

Last_Slip_No = 0

Dim dbsSlipper as Database
Dim rstSlips as Recordset

set dbsSlipper = CurrentDb
set rstSlips = dbsSlipper.Execute ("SELECT SlipNo FROM tblSlips ORDER BY SlipNo")

if rstSlips.RecordCount > 0 then
rstSlips.movelast
Last_Slip_No = rstSlips.fields![SlipNo]
end if

rstSlips.close
dbsSlipper.close

End Function
------------------------End code example

This function example should return a number to a calling function that should check for a returned value of 0 (zero), which would indicate an error.

This all for if you want the check performed at a data-entry level.

If you want a data entry check done, you could use the above code with minor changes to fill a text string with the slip numbers that have not been entered within a range.
Another consideration is (if this is a multi-user situation), if another user may be entering the missing number while the check is being run...

Hope it helps
TimFox
(another posting with more info might help if I have missed the point)

by spidee

You need to use a temporary table:

1. Add a temporary table that stores the slip#.
2. Create a function where everytime a user updates the slip# from the main table, it also updates the temporary table.
3. So next time the user updates/inserts the next slip #, you need to compare the slip# field in the temporary table and your main table if >2

Hope this works.

by kees.valkenswaard

Well, your problem could perhaps be solved with a query without any VBA.
Suppose you have the slip numbers and other info in a table T. Make sure that field slip is the primary key to avoid duplicates.
Design a query D based on table T. In the grid add field slip and two additional fields:
Plus: [slip] + 1
Min: [slip] ? 1
Sorting ascending for slip may be useful
Design a query Overview based on table T, query D and once more query D which will be called D_1
Remove the links between the slip field. Make a new link between slip in T and plus in D. Change the join type to show all records in T. Also a link between slip in T and min in D_1 with the same join type.
Enter into the grid field slip from T ascending.
Add a new visible field:
What: IIf(IsNull([D].[plus]);IIf(IsNull([D_1].[min]);"start/end";"start");"end")
NOTE If you apply the old-fashioned non-standard US-system ; [semi-colon] may have to be replaced by , [comma]
Add field plus from D with criteria is null
Add field min from D1 with criteria is null on the next line in the grid
Both fields should be invisible [the check box cleared]
Suppose T contains the following slip numbers:
3-5, 7, 9-10, 13, 15-17, 34-120, 140, 150-2000
The query overview would yield:
slip What
3 start
5 end
7 start/end
9 start
10 end
13 start/end
15 start
17 end
34 start
120 end
140 start/end
150 start
2000 end

Good luck

by kees.valkenswaard

If you want to check at input a macro would be required to compare the number with the maximum of the numbers already added. This would require real sequential entering of the slips. My query would allow non sequential entering, showing afterwards what is missing.

by kees.valkenswaard

If you want that Access warns you that the number is not he highest + 1 that would also require a macro. If you design a form it is not that complicated to offer as default the value Highest + 1. However, what are you going to do if the number is highest + N [N>1]. Taking a pencil to write down that you missed one? I still think that my query would be useful. If you print the result you know at least which ones are missing.
If you want to mail me put Q&A as part of the subject line. Else the message would be deleted with this address.

This discussion is closed to new replies.