using the system.mdw file makes it easier to write programs that leave the database locked after the program exits.
The following modification to the demo seems to overcomes the “Record(s) cannot be read; no read permission on MSysObjects” problem without needing to change the security on the database though Access Menus.
use header #include "AFXDAO.H" to use the DAO functions and classes below
************************************************************************
In CAccessReportViewerDoc.cpp add function
void SetSystemDB( CString & strSystemMDB )
{
COleVariant varSystemDB( strSystemMDB, VT_BSTRT );
// Initialize DAO for MFC
AfxDaoInit( );
DAODBEngine* pDBEngine = AfxDaoGetEngine( );
ASSERT( pDBEngine != NULL );
// Call put_SystemDB method to set the
// system database for DAO engine
DAO_CHECK( pDBEngine->put_SystemDB( varSystemDB.bstrVal ) );
}
and modify function
BOOL CAccessReportViewerDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
//modify this to point to your system.mdw
CString strSystemDB =
_T( "C:\\Documents and Settings\\John\\Application Data\\Microsoft\\Access\\System.mdw" );
static bool bSetSystemDB=false;
if(bSetSystemDB==false)
{
SetSystemDB( strSystemDB );
bSetSystemDB=true;
}
if (!CDocument::OnOpenDocument(lpszPathName))
return FALSE;
m_pAccessReports = new CAccessReports(lpszPathName, TRUE);
return TRUE;
}
*********************************************************************************
In CAccessReportViewerDoc.cpp add and modify function
int CAccessReportViewerApp::ExitInstance()
{
// TODO: Add your specialized code here and/or call the base class
//terminates the DAO database engine
AfxDaoTerm( );
return CWinApp::ExitInstance();
}
他是怎么不通过ACCESS的菜单而自动获取这个表的权限的呢???
------解决方案--------------------------------------------------------
VB可以直接访问dao,不需要这么啰嗦的代码。