两个数据库进行交互,在其中一个数据库中,打开另一个数据库的窗体~
Private Declare Function apiShowWindow Lib "user32" Alias "ShowWindow" _
(ByVal hwnd As Long,ByVal nCmdShow As Long) As Long
Private Declare Function SetForegroundWindow Lib "user32" _
(ByVal hwnd As Long) As Long
'dbname为打开数据库的完整名称如c:\1.mdb
'frmname为要开启数据库的表单,如test
'用法为opendbfrm("c:\1.mdb","test")
function openDbFrm(byval dbName as string,byval frmName as string)
Dim appAccess As Object
Dim xx As Long
Set appAccess = GetObject(dbName)
if not appAccess.Visible then appAccess.Visible = True
'成为前台
xx = SetForegroundWindow(appAccess.hWndAccessApp)
'最大化数据库
xx=apiShowWindow(appAccess.hWndAccessApp,3)
'打开窗体
appAccess.DoCmd.OpenForm frmName
'最大化窗体
DoCmd.Maximize
'释放物件
set appAccess=nothing
End function
也就是说,只要定义了一个access.application物件,就可以控制另一个数据库,稍作修改,即可以打开报表,查询等
唯一存在的缺陷是,有时候物件不能完全释放;打开的数据库跟当前窗口是同一数据源时,会有所冲突
请大家完善
[此贴子已经被作者于2003-1-8 15:36:26编辑过]
|