RE: Giúp mình khai báo reference trong access . cụ thể là " Microsoft Excel Object librar
duong100 > 13-06-14, 12:22 AM
Thử cái này:
'==========
Function FixUpRefs()
Dim loRef As Access.Reference
Dim intCount As Integer
Dim intX As Integer
Dim blnBroke As Boolean
Dim strPath As String
On Error Resume Next
'Count the number of references in the database
intCount = Access.References.Count
'Loop through each reference in the database
'and determine if the reference is broken.
'If it is broken, remove the Reference and add it back.
Debug.Print "----------------- References found -----------------------"
Debug.Print " reference count = "; intCount
For intX = intCount To 1 Step -1
Set loRef = Access.References(intX)
With loRef
Debug.Print " reference = "; .FullPath
blnBroke = .IsBroken
If blnBroke = True Or Err <> 0 Then
strPath = .FullPath
Debug.Print " ***** Err = "; Err; " and Broke = "; blnBroke
With Access.References
.Remove loRef
Debug.Print "path name = "; strPath
.AddFromFile strPath
End With
End If
End With
Next
'''Access.References.AddFromFile "C:\Program Files\Common Files\Microsoft Shared\DAO\dao360.dll"
Set loRef = Nothing
' Call a hidden SysCmd to automatically compile/save all modules.
Call SysCmd(504, 16483)
End Function
Function AddRefs()
Dim loRef As Access.Reference
Dim intCount As Integer
Dim intX As Integer
Dim blnBroke As Boolean
Dim strPath As String
On Error Resume Next
'Loop through each reference in the database
'Add all references
Debug.Print "----------------- Add References -----------------------"
With Access.References
.AddFromFile "C:\Program Files\Common Files\Microsoft Shared\DAO\dao360.dll"
.AddFromFile "C:\Program Files\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll"
.AddFromFile "C:\Program Files\Microsoft Office\Office\msacc9.olb"
.AddFromFile "C:\Program Files\Common Files\System\ado\msado15.dll"
.AddFromFile "C:\Program Files\Common Files\System\ado\msado25.tlb"
.AddFromFile "C:\Program Files\Common Files\System\ado\msadox.dll"
.AddFromFile "C:\WINNT\System32\stdole2.tlb"
.AddFromFile "C:\WINNT\System32\scrrun.dll"
'===========
.AddFromFile "= C:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXE" ' Đặt Excel
.AddFromFile "= C:\Program Files\Common Files\System\ado\msador28.tlb"
.AddFromFile "= C:\Program Files\Common Files\System\ado\msado28.tlb"
.AddFromFile "= C:\Program Files\Common Files\Microsoft Shared\DAO\dao360.dll"
.AddFromFile "= C:\Program Files\Common Files\Microsoft Shared\OFFICE15\MSO.DLL"
.AddFromFile "= C:\Program Files\Microsoft Office\Office15\MSACC.OLB"
.AddFromFile "= C:\PROGRA~1\COMMON~1\MICROS~1\VBA\VBA7.1\VBE7.DLL"
End With
' Call a hidden SysCmd to automatically compile/save all modules.
Call SysCmd(504, 16483)
End Function