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("patien t.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.Ge tFileName( ));
}
catch (CDaoException* e)
{
// Tell them the reason it failed to open
AfxMessageBox(e->m_pErrorI nfo->m_str Descriptio n);
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;
}
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("patien
}
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.Ge
}
catch (CDaoException* e)
{
// Tell them the reason it failed to open
AfxMessageBox(e->m_pErrorI
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
{
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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?
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.
Try giving a full path when you open the file.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
split between all experts
Sorry, I meant DAO 3.6, not 3.5.