Hi,
Was trying to implement my own random autonumber function that only
produced positives... got this code from another poster but I can't
get it to work.
How do I refer to this function? I have been trying:
=LongIDCreate ([July Invoices], [InvoiceID])
A box, like for a parameter, asking for entry for [July Invoices]
keeps popping up! July Invoices is the table name and I"m trying to
tell the function that!
Help?
Function Code Is:
Function LongIDCreate(ByVal vstrTable As String, ByVal vstrField As
String) As Long
On Error GoTo LongIDCreate_Err
Dim ws As Workspace
Dim db As Database, dbOrg As Database
Dim rst As Recordset
Dim lngTemp As Long
Dim fDone As Integer
Const MAX_LONG = &HFFFFFFF
Randomize
Set db = CurrentDb()
Do While Not fDone
lngTemp = Abs(CLng(MAX_LONG * Rnd)) ' just positive numbers
(remove Abs for pos & neg)
Set rst = db.OpenRecordset("SELECT [" & vstrField & "] FROM "
& vstrTable & " WHERE [" & vstrField & "]=" & lngTemp & ";")
If (rst.BOF And rst.EOF) Then '** Check for uniqueness
fDone = True
End If
rst.Close
Loop
LongIDCreate = lngTemp
LongIDCreate_Exit:
Exit Function
LongIDCreate_Err:
Call ErrorHandler(mcModuleName & ".LongIDCreate")
Resume LongIDCreate_Exit
End Function