dbFailOnExecute

  • Thread starter Thread starter Guest
  • Start date Start date
I think you may be confusing the Execute method with dbFailOnError.

The Excute method is much like the Docmd.RunSQL, only better. It executes
SQL action queries, but without going through the Access User Interface. It
goes directly to Jet. The dbFailOnError causes an error to be rasied if the
SQL could not be succesfully completed.

Here is an example:
CurrentDb.Execute "DELETE * FROM dept550TopPct;", dbFailOnError
 
I used the following:

CurrentDb.Execute "DELETE * FROM tblItems WHERE [ItemID] = " _
& lstBEItems.Value, dbFailOnExecute

It worked fine and I was able to trape the error if the record was already
deleted, but I had to turn Option Explicit off. I found dbFailOnExecute with
the object browser under globals.

Why would I get a compile error, variable not defined, if it is already a
global thing?

Thanks,
sjw
 
sjw said:
I used the following:

CurrentDb.Execute "DELETE * FROM tblItems WHERE [ItemID] = " _
& lstBEItems.Value, dbFailOnExecute

It worked fine and I was able to trape the error if the record was
already deleted, but I had to turn Option Explicit off. I found
dbFailOnExecute with the object browser under globals.

Why would I get a compile error, variable not defined, if it is
already a global thing?

There is no "dbFailOnExecute", unless you defined some such thing. The
defined DAO constant is dbFailOnError.
 
I have never heard of or can find any reference to dbFailOnExecute.
Someone invented that in your application.
You don't have to have Option Explicit off. I don't ever have a module
without it. It is a great safety net.

Change your code to use dbFailOnError and put Option Explicit back in.
Also, there are two issues with this reference:
lstBEItems.Value

First, you don't need the Value property. It is the default, and more
important, you should always qualify your control names with the form name.
Assuming the code is in the form module, it should be:
Me.lstBEItems
 
Thanks Klatuu,
I'll make the changes.

Klatuu said:
I have never heard of or can find any reference to dbFailOnExecute.
Someone invented that in your application.
You don't have to have Option Explicit off. I don't ever have a module
without it. It is a great safety net.

Change your code to use dbFailOnError and put Option Explicit back in.
Also, there are two issues with this reference:
lstBEItems.Value

First, you don't need the Value property. It is the default, and more
important, you should always qualify your control names with the form name.
Assuming the code is in the form module, it should be:
Me.lstBEItems



sjw said:
I used the following:

CurrentDb.Execute "DELETE * FROM tblItems WHERE [ItemID] = " _
& lstBEItems.Value, dbFailOnExecute

It worked fine and I was able to trape the error if the record was already
deleted, but I had to turn Option Explicit off. I found dbFailOnExecute with
the object browser under globals.

Why would I get a compile error, variable not defined, if it is already a
global thing?

Thanks,
sjw
 
Back
Top