P
provoked
Guest
Hi guys,
Cool forum, my first post.
Just wondering if anyone can help me with this, as ive searched the forums and have found nothing helpful.
I have a small database, which a table called family, (a family enrolls student and pays fee kind of DB). Anyway, ive created some VBA code to create a key that consists of the first three letters of their surname, the year (05) and an auto generated number. Ive used this code.
-----------------------------------------------------------------------
Private Sub family_name_AfterUpdate()
Dim randNumb As Integer
randNumb = Int((999 - 100 + 1) * Rnd + 100)
family_id = Left(family_name, 3) + Right(Date, 2) + CStr(randNumb)
End Sub
-----------------------------------------------------------------------
My problem is, that even though a duplicate key is near impossible, i dont like the possibility of it occuring, therefore i need to check to see if that ID currently exists. Ive tryed the following code, which allowed duplicates.
-----------------------------------------------------------------------
Do While match = True
For i = 0 To rst.EOF
If (temp = rst!family_id) Then
match = True
rst.MoveFirst
i = 0
randNumb = Int((6 - 1 + 1) * Rnd + 1)
temp = Left(family_name, 3) + Right(Date, 2) + CStr(randNumb)
Else
rst.MoveNext
End If
If (i = rst.EOF = True) Then
match = False
Exit Do
End If
Next i
Loop
family_id = temp
------------------------------------------------------------------------
Im now stuck. Im not just asking for answers or my problem solved, even if someone can give me some direction?
Any help would be greatly appreciated.
Cheers!
Cool forum, my first post.

I have a small database, which a table called family, (a family enrolls student and pays fee kind of DB). Anyway, ive created some VBA code to create a key that consists of the first three letters of their surname, the year (05) and an auto generated number. Ive used this code.
-----------------------------------------------------------------------
Private Sub family_name_AfterUpdate()
Dim randNumb As Integer
randNumb = Int((999 - 100 + 1) * Rnd + 100)
family_id = Left(family_name, 3) + Right(Date, 2) + CStr(randNumb)
End Sub
-----------------------------------------------------------------------
My problem is, that even though a duplicate key is near impossible, i dont like the possibility of it occuring, therefore i need to check to see if that ID currently exists. Ive tryed the following code, which allowed duplicates.
-----------------------------------------------------------------------
Do While match = True
For i = 0 To rst.EOF
If (temp = rst!family_id) Then
match = True
rst.MoveFirst
i = 0
randNumb = Int((6 - 1 + 1) * Rnd + 1)
temp = Left(family_name, 3) + Right(Date, 2) + CStr(randNumb)
Else
rst.MoveNext
End If
If (i = rst.EOF = True) Then
match = False
Exit Do
End If
Next i
Loop
family_id = temp
------------------------------------------------------------------------
Im now stuck. Im not just asking for answers or my problem solved, even if someone can give me some direction?
Any help would be greatly appreciated.
Cheers!