Excel 2010 VBA Error: Compile error User-defined type not defined

TomTTT

New Member
Joined
Nov 11, 2011
Messages
8
Hi,

I'm seeking to run some VBA code in Excel 2010 on a Windows XP machine. The goal of the code is to take a large Excel file and break it down into a set of distinct files (e.g. Report_Department100, Report_Department200, Report_Department300) which will then be examined and emailed out to the various departments.

Here is the error I get when I attempt to run it: "Compile error: User-defined type not defined." Excel highlights the "Dim DB As Database" line specifically.

Here is the context of the code:

Code:
Sub CreateFiles()

Dim DB As Database
Dim rst As Recordset
Dim rst2 As Recordset
Dim strSQL As String
Dim DeptID As String
Dim CustID as DAO.QueryDef
Dim FilePath As String
What do you suggest I do to address this problem?
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Hi Tom
Welcome to the board

You must be missing (at least) one reference.

Check the documentation of the code you are using.

In the VB Editor, in Tools->References you must set the appropriate references. My first guess is Microsoft DAO Object Library
 
Upvote 0
Hi PGC,

Thanks for your prompt reply. I followed your suggestion and added a reference to "Microsoft DAO 3.6 Object Library." When I ran the code again, there was no compile error.

However, another error has come up.
Error: run-time error 424: Object required.

When I hit debug, VB Editor points to this line:

Code:
Set DB = CurrentDb
 
Upvote 0
CurrentDb belongs to Access, not Excel.
 
Upvote 0

Forum statistics

Threads
1,223,247
Messages
6,171,007
Members
452,374
Latest member
keccles

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top