473,473 Members | 2,179 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Can't get this function to work?

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
2 1308
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: .: DeVa :. | last post by:
I made a script for loging into members area and have one problem im using functions() to declare procedures to do... And when i want to use some variable that is out of the function it doesent...
2
by: Lian Liming | last post by:
Hi, all I want to write my own error handler function in php by using "set_error_handler()" function. I have made a test for this function but found it did not work. My test code is as following:...
3
by: OM | last post by:
Why doesn't a onmouseover function work in a function? (It's prob due to my code being wrong more than anything else!) I've got the following code (snippet): <!-- Begin var image0 = new...
2
by: F. Da Costa | last post by:
Hi, I'm trying to call/ mimic an onchange function/ event after a user has clicked a checkbox. In response to which a buncch of other ones need to be checked as well. The caveat is that each of...
1
by: Allen | last post by:
I am trying to add an additional photo/hyperlink to the company web site (I didn't create it) without any luck. The mouseover feature 'highlights' pics by swapping them with another pic using this...
39
by: Randell D. | last post by:
Folks, I'm sure this can be done legally, and not thru tricks of the trade - I hope someone can help. I'm writing a 'tool' (a function) which can be used generically in any of my projects. ...
2
by: Steve Crawford | last post by:
Having a requirement to change null into a certain value in a query I created a couple versions of an ifnull function as follows: create or replace function "ifnull" (text, text) returns text as...
2
by: Schorschi | last post by:
Can't seemd to get ReadFile API to work! Returns invalid handle error? =========================================================================== Ok, the visual basic gurus, help! The...
52
by: MP | last post by:
Hi trying to begin to learn database using vb6, ado/adox, mdb format, sql (not using access...just mdb format via ado) i need to group the values of multiple fields - get their possible...
8
by: Yakov | last post by:
I'd like a tool that performed inlining of function bodies of which do not appear in the .h file. Really. gcc on Linux. Yakov
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.