Do Until Loop

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a Data Entry Form used to only add records, one of the fields on it is
a Drawing Number which is the primary key. After they enter a Drawing Number
and click the Save button I want to Loop through the table to that form and
check to see if the Drawing Number already exists. I am not too familiar
with Loop statements and can't get the one I have to work. Anyone know how I
would loop through the table to check and see if they are creating a
duplicate Drawing Number?
 
I have a Data Entry Form used to only add records, one of the fields on it is
a Drawing Number which is the primary key. After they enter a Drawing Number
and click the Save button I want to Loop through the table to that form and
check to see if the Drawing Number already exists. I am not too familiar
with Loop statements and can't get the one I have to work. Anyone know how I
would loop through the table to check and see if they are creating a
duplicate Drawing Number?

Why don't you simply set the table [DrawingNumber] field to Indexed(No
Duplicates) ?
Access won't allow you to enter the same value twice.

If you don't wish to use the NoDuplicates, as suggested above:
To determine if a record with a DrawingNumber already exists, you
could let Access do the work.
This must be done before the record is actually saved, otherwise it
will exist in the table, right?

In the Form's BeforeUpdate event:
If DCount("*","TableName","[DrawingNumber] = " & Me![DrawingNumber]) >
0 Then
MsgBox "This number is in use."
Cancel = True
End If

If the number already exists, the record is not saved.

I'll give you an example of a loop, though you don't need this to do
what you wish.

Dim intX
intX = 1
Do while intX <= 10
MsgBox intX
intX = intX + 1
Loop
 
Try using the DLookup function to see if the value already exists in the
table. See DLookup in Help file.
 
Back
Top