Iain:
To call a function as an event property you do, as you assumed, enter the
function name in the properties sheet in place of [Event Procedure] or a
macro name, but you precede it with an equals sign. The values required by
the function as its arguments are placed within the parentheses following the
function name. In the example I gave you these are references to controls on
a dialogue form in which you select or enter the value for each argument, so
you'd enter the following, all as one line, as the event property:
=InsertDocuments([cboLibIndex],[cboStatus],[cboDocPrefix],[txtDocStartNumber],
[txtNumberOfDocs])
As regards building the SQL statement the following is the line of code as a
single line, though it will have been split into several by your newsreader
when you read it:
strSQL = "INSERT INTO [DocumentsTable] ([LibraryIndex],[Status],
[DocumentNumber]) VALUES(" & lngLibraryIndexNumber & ",""" & Status & ""","""
& DocPrefix & "_" & DocStartNumber + n & """)"
Looking at it again as written in the function over four lines for better
readability:
strSQL = "INSERT INTO [DocumentsTable]" & _
"([LibraryIndex],[Status],[DocumentNumber]) " & _
"VALUES(" & lngLibraryIndexNumber & ",""" & _
Status & """,""" & DocPrefix & "_" & DocStartNumber + n & """)"
what might be confusing you is that ampersands are used before the underscore
continuation characters at the ends of the first two lines to concatenate the
literal strings "INSERT INTO [DocumentsTable]" and "([LibraryIndex],[Status],
[DocumentNumber]) ", so these are not part of the expression when written as
one unbroken line, but the ampersand at the end of the third line
concatenates the value of the variable Status with the preceding literal
string ",""", so is included as part of the expression when written as one
unbroken line.
I have tested the function as posted and can confirm that it does insert the
rows into a table named DocumentsTable with the correct values in the
relevant columns.
Ken Sheridan
Stafford, England
I understand the point about defaulting to a variant and not returning a value.
I'm unsure about what you mean by calling it as an event property. Are you
saying that the event property box contains the function name and not the
words [Event Proceedure]?
The ADO library is selected.
When I try to run the code I receive a message box requesting the parameter
value for n which has to be entered for each pass of the loop. Even if
these values are entered manually the program simply inserts the same
document number for each pass of the loop. So for some reason the document
number is not incrementing.
I understand the use of parenthesis arround the VALUES and use of amepersand
as a cocatenation operator but couldn't follow the syntax clearly.
Appologies for misleading you. I meant to type 'quotation marks' not
'parenthesis'.
I am however, still very confused by the quotation marks and ampersands. and
may have mistakenly typed this statement when trying to correct the syntax
errors I received when I first inserted my object names into the code.
It seemed to me that there were too many ampersands and I would have
expected alternating use of single and double quotations. I couldn't make
sense of why some of the ampersands are required if constructing what is
simply a string.
Is it possible for you to retype this statement as one line using
alternating quotation marks (if that works for this statment) so that I can
see what is going together with what. I tried to do this and I think this
may be where I've gone wrong.
Sorry to be a pain (Can't teach an old dog new tricks I suppose)
Regards,
Iain
It defaults to a variant if the function is not declared as a specific data
type. The function in this case is not intended to return any value. The
[quoted text clipped - 46 lines]