Cameron Eckman wrote ...
>I asked this before but unfortunately I didn't get back to the newsgroup
>soon enough. I am using VB5 and storing data in a DAO 3.5 database (Access
>97).
>I would like to do the following query in code:
> UPDATE PlotRecords SET PlotRecords.Accounting =
>FirstNumberSeries(PlotRecords.PlotName);
>The problem I have is that FirstNumberSeries is a public function defined
in
>the VB5 code and I get the message:
>"Undefined function 'FirstNumberSeries' in expression."
>I have tried to put the FirstNumberSeries in a code module in the mdb file
>with no luck either. I would prefer to avoid creating a recordset and
>walking through each record (or would that be faster?). Could someone
>please give some me guidance. Thanks.
>Cameron A. Eckman
You can't have a function embedded in your sql statement.
It has to do with the fact that the Jet Engine evaluates
SQL statements and your user-defined function is not
an SQL statement.
However, since all Jet is asking for is an SQL statement
(a string) why not do the following:
...
dim db as database
dim strSQL as string
set db = DBEngine.Workspaces(0).OpenDatabase("Your database", etc...)
' Build the SQL statement using concatenation ...
strSQL = "UPDATE PlotRecords SET PlotRecords.Accounting = '" & _
FirstNumberSeries(PlotRecords.PlotName) & "';"
db.Execute strSQL
...
This is assuming that your function FirstNumberSeries() returns a string
value.
The public function will ve evaluated by VB and you will be sending
an SQL statement to JET.
Now, let's assume your function returns the following: "whatever"
your SQL statement (strSQL) would then be:
UPDATE PlotRecords SET PlotRecords.Accounting = 'whatever';
Hope this helps !
Robert Ayotte
Montreal