By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,495 Members | 1,158 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,495 IT Pros & Developers. It's quick & easy.

Can't get this function to work?

P: n/a
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
Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Crispywafers" <cr**********@yahoo.com> wrote in message
news:39**************************@posting.google.c om...
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!


Those arguments are strings. Try putting quotes around them.
--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Nov 13 '05 #2

P: n/a
Not only are the arguments strings, so you must put them in quotes, but
the table name has a blank in it, so you should change

OpenRecordset("SELECT [" & vstrField & "] FROM "
& vstrTable & " WHERE [" & vstrField & "]=" & lngTemp & ";")

to

OpenRecordset("SELECT [" & vstrField & "] FROM ["
& vstrTable & "] WHERE [" & vstrField & "]=" & lngTemp & ";")

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.