Using Function in a different database

G

Guest

Hi,

I'm sure this is an easy one, but I'm not really up on code.

I have the following code that I picked up from this discussion board, which
works perfectly in the database I first used it in. It is very helpful to me
as it gets rid of any ImportErrors tables I might have (I generate quite a
lot of these as my header/footer records differ from the data records).

However, when I copy the function (as part of a module) into another
database and attempt to run/compile I get:

"Compiler Error: User defined type not defined" on the line that reads
"Dim db As Database"

Could someone please offer some idiot-proof advice on how to correct this?
Be aware that you're dealing with a reasonably high-standard of idiot, but a
poor standard of DBA :)

Thnaks in advance,
Mike


Function Delete_ImportErrors()

Dim db As Database
Dim tdf As TableDef

Set db = CurrentDb

For Each tdf In db.TableDefs
If tdf.Name Like "*_ImportErrors*" Then
DoCmd.DeleteObject acTable, tdf.Name
End If
Next
End Function
 
D

Duane Hookom

You most likely need to set a reference to the Microsoft DAO object library.
Open any module and select Tools | References and check this library. Then
change your code to be explicit:

Dim db As DAO.Database
Dim tdf As DAO.TableDef
 
G

Guest

Thanks Duane,

As we say in Australia, "it works like a bought one!" :)

This is the first NEW database I've put together in a long time - I normally
copy one to another to retain the same form & report look. Interestingly, it
would appear that this must be where I've "lost" my references, as I never
have to look at them. One to remember for the future, and it's no doubt
avoided further grief further down the line as other code would apparently
cease to work.

Thanks again, to you and the many other posters whose advice I've been
silently absorbing over the past couple of months.

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top