Link to home
Start Free TrialLog in
Avatar of hlaith
hlaith

asked on

DAO Database, Open .mdb file?

Hi..

I am using the following code to open an access database file (.mdb) but when i run the application and choose the databse file it say "Unrecognized database format...." , can anyone give a hand into this please?

here is the code:

BOOL CPatientDoc::OnNewDocument()
{
      if (!m_DataBase.IsOpen())
      {
            // First assume patient.mdb file is in current directory
            try
            {
                  m_DataBase.Open(_T("patient.mdb"));
            }
            catch (CDaoException* e)
            {
                  // Assume failure is becauase we couldn't find the file
                  e->Delete();
            }
      }
      if (!m_DataBase.IsOpen())
      {
            // Now pop-up file-open dlg to ask for location
            CFileDialog dlgFile(
                  TRUE,
                  _T(".mdb"),
                  NULL,
                  OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
                  _T("Access Files (*.mdb)|*.mdb|All Files (*.*)|*.*||"));
            if (dlgFile.DoModal() == IDCANCEL)
                  return FALSE;
            try
            {
                  m_DataBase.Open(dlgFile.GetFileName());
            }
            catch (CDaoException* e)
            {
                  // Tell them the reason it failed to open
                  AfxMessageBox(e->m_pErrorInfo->m_strDescription);
                  e->Delete();
                  return FALSE;
            }
      }
      if (!m_DataBase.IsOpen())
            return FALSE;
      m_pPatientSet = new CPatientSet(&m_DataBase);
      m_pPatientSet->Open();

      if (!CDocument::OnNewDocument())
            return FALSE;
      
      CConnectDlg dlg;
      if( dlg.DoModal() == IDOK )
      {
         if( dlg.m_SerCli == 0 )
         {
                  if( m_pMainSocket == NULL )
                  {
                        m_pMainSocket = new CMainSocket(this);
                        if (m_pMainSocket->Create(dlg.m_Port))
                        {
                              if (!m_pMainSocket->Listen())
                              {
                                    AfxMessageBox( "Verify Connection!." );
                                    return FALSE;
                              }
                        }
                  }
         }
         else if( dlg.m_SerCli == 1 )
         {
                  ConnectSocket( dlg.m_IPStr , dlg.m_Port );
         }
         m_SerCli = dlg.m_SerCli;
         m_IPStr = dlg.m_IPStr;
         m_Port = dlg.m_Port;
      }
      else
            return FALSE;

      if (!CDocument::OnNewDocument())
            return FALSE;

      return TRUE;
}
ASKER CERTIFIED SOLUTION
Avatar of Axter
Axter
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jimwasson
jimwasson

force" MFC to use DAO 3.5

Sorry, I meant DAO 3.6, not 3.5.
Avatar of hlaith

ASKER

Hi i have converted the mdb file to Access 97 format, but still gives me the same error ...

I also tried placing the code in initinstance(), but i got the following error:

 'm_dwVersion' : is not a member of 'AFX_MODULE_STATE'


Any suggestions?
Are you sure you're opening the right file.

Try giving a full path when you open the file.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
split between all experts