I know DAO can compact database, not sure if you can do it via ODBC.Microsoft Visual C++ sample using Microsoft Foundation Classes (MFC) DAO classes: This is a standard Microsoft Visual C++ application that supports MFC.
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif///////////////////////////////////////////////////////////////////////////// 
// The one and only application objectCWinApp theApp;
using namespace std;int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0; // initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
    // TODO: change error code to suit your needs
    cerr << _T("Fatal Error: MFC initialization failed") << endl;
    nRetCode = 1;
}
else
{
   CDaoDatabase db;
   try{
        db.m_pWorkspace->CompactDatabase(_T("C:\\MyMDB\\Sample.mdb"),
                                                  _T("C:\\MyMDB\\CompactedSample.mdb"),dbLangGeneral,dbVersion30,";pwd=YourPassword");
   }
   catch (CDaoException *e)
   {
        AfxMessageBox (e->m_pErrorInfo->m_strDescription);
        e->Delete();
       }
   return nRetCode;
}

BUG: Database Compaction with SQLConfigDataSource Fails when Access Database is Password Protected Q270638