>>Phil
>
>
> How do you use your table Phil?
>
> Thanks!
>
> -paulw
>
Sorry Paul. This is a lot of code and there will probably be some stuff
missing
Basically an AutoExec Macro runs the LoadRefs function on starting Access and
when I close the program via a command button, the UnloadRefs runs
Phil
Option Compare Database
Option Explicit
Private Declare Function apiGetComputerName Lib "kernel32" Alias _
"GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Function fOSMachineName() As String
'Returns the computername
Dim lngLen As Long, lngX As Long
Dim strCompName As String
lngLen = 16
strCompName = String$(lngLen, 0)
lngX = apiGetComputerName(strCompName, lngLen)
If lngX <> 0 Then
fOSMachineName = Left$(strCompName, lngLen)
Else
fOSMachineName = ""
End If
End Function
Function LoadRefs()
' Run by AutoExec Macro
Dim MyDb As Database
Dim RefsSet As Recordset
Dim SQLStg As String
Dim RefsFixed As Boolean
' Make sure this reference is loaded for this computer
SQLStg = "SELECT Refs.* FROM Refs "
SQLStg LStg = SQLStg & "WHERE ComputerName = '" & fOSMachineName() & "' ORDER
BY Refs.Sequence;" ' This computer name
Set MyDb = CurrentDb
Set RefsSet = MyDb.OpenRecordset(SQLStg)
With RefsSet
Do Until .EOF
RefsFixed = FixUpRefs(!RefName, !RefPath)
.MoveNext
Loop
.Close
Set RefsSet = Nothing
End With
'RefsFixed ixed = FixUpRefs("Menu 2010", "C:\Phil Data\Access\MDB 2010\Menu
2010.AccDe ) End Function
Sub CheckRefName()
Dim MyDb As Database
Dim RefsSet As Recordset
Dim SQLStg As String
Dim Ref As Reference
Dim i As Integer
' Make sure this reference is loaded
SQLStg = "SELECT Refs.* FROM Refs "
SQLStg = SQLStg & "WHERE ComputerName = '" & fOSMachineName() & "';"
Set MyDb = CurrentDb
Set RefsSet = MyDb.OpenRecordset(SQLStg)
' Need to make sure we have the latest version of any library reference
With RefsSet
Do Until .EOF
For i = Access.References.Count To 1 Step -1
Set Ref = Access.References(i)
If Ref.FullPath = !RefPath Then
.Edit
!RefName = Ref.Name
.Update
End If
Set Ref = Nothing
Next i
.MoveNext
Loop
.Close
Set RefsSet = Nothing
End With
End Sub
Function UnLoadRefs()
'If IsItMDE Then Exit Function
Dim MyDb As Database
Dim RefsSet As Recordset
Dim SQLStg As String
Dim Ref As Reference
Dim i As Integer
' Make sure this reference is loaded
SQLStg = "SELECT Refs.* FROM Refs "
SQLStg LStg = SQLStg & "WHERE ComputerName = '" & fOSMachineName() & "' ORDER
BY Refs.Sequence;" ' This computer name
Set MyDb = CurrentDb
Set RefsSet = MyDb.OpenRecordset(SQLStg)
' Need to make sure we have the latest version of any library reference
With RefsSet
Do Until .EOF
For i = 1 To References.Count
If References(i).Name = !RefName Then ' Find the name
Set Ref = References(i)
References.Remove Ref ' Remove it
Set Ref = Nothing
Exit For
End If
Next i
.MoveNext
Loop
.Close
Set RefsSet = Nothing
End With
RunCommand acCmdCompileAndSaveAllModules
End Function
Function FixUpRefs(Optional ExtraRefName$, Optional ExtraRefPath$) As Boolean
' Ensure extra reference is loaded. ExtraRef is the name
If IsItMDE Then Exit Function
Dim Ref As Access.Reference
Dim intCount As Integer
Dim intX As Integer
Dim blnBroke As Boolean
Dim strPath As String
On Error GoTo FixUpRefs_Error
'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.
For intX = intCount To 1 Step -1
Set Ref = Access.References(intX)
With Ref
blnBroke = .IsBroken
If blnBroke = True Or Err <> 0 Then
strPath = .FullPath
With Access.References
.Remove Ref
.AddFromFile strPath
End With
End If
End With
Set Ref = Nothing
Next intX
If ExtraRefPath > "" Then
For intX = intCount To 1 Step -1
Set Ref = Access.References(intX)
If If Ref.Name = ExtraRefName Or Ref.FullPath = ExtraRefPath Then ' Reference
found References.Remove Ref
References.AddFromFile ExtraRefPath
Else
References.AddFromFile ExtraRefPath
End If
Next intX
End If
Set Ref = Nothing
'Call Call SysCmd(504, 16483) hidden SysCmd to automatically compile/save all
modules.
RunCommand acCmdCompileAndSaveAllModules
FixUpRefs = True
Call Call CheckRefName ' Make sure names are loaded to refs table
Exit Function
FixUpRefs_Error:
If Err = 2046 Then ' In AccDe so can't compile
Resume Next
ElseIf Err = 29060 Then ' File not found
If strPath > "" Then
MsgBox Err & " File " & strPath & " not found"
Else
MsgBox Err & " File " & ExtraRefPath & " not found"
End If
ElseIf seIf Err = 32813 Then ' Name conflicts with existing module, project,
or object library Resume Next
Else
MsgBox MsgBox "Error " & Err.Number & " (" & Err.Description & ") in
procedure FixUpRefs of Module ModReferences" End If
End Function
Sub AddRefs()
If IsItMDE Then Exit Sub
On Error Resume Next
'Loop through each reference in the database
'Add all references
'Debug.Print "----------------- Add References -----------------------"
'Word :C:\Program Files (x86)\Microsoft Office\Office14\MSWORD.OLB
'Outlook :C:\Program Files (x86)\Microsoft Office\Office14\MSOUTL.OLB
'MSComctlLib :C:\Windows\SysWow64\MSCOMCTL.OCX
'VBIDE BIDE :C:\Program Files (x86)\Common Files\Microsoft
Shared\VBA\VBA6\VBE6EXT.OLB 'Office :C:\Program Files (x86)\Common
Files\Microsoft Shared\OFFICE14\MSO.DLL 'Menu 2010 :C:\Phil Data\Access\MDB
2010\Menu 2010.accdb 'DAO :C:\Program Files (x86)\Common Files\Microsoft
Shared\OFFICE14\ACEDAO.DLL 'stdole :C:\Windows\SysWOW64\stdole2.tlb
'Access :C:\Program Files (x86)\Microsoft Office\Office14\MSACC.OLB
'VBA :C:\PROGRA~2\COMMON~1\MICROS~1\VBA\VBA7\VBE7.DLL
' Standard References - Others fount in table Refts for this database
' ****** ORDER IS IMPORTANT ******* '
With Access.References
AddFromFile FromFile " C:\Program Files (x86)\Common Files\microsoft
shared\VBA\VBA7\VBE7.DLL" .AddFromFile " C:\Program Files (x86)\Microsoft
Office\Office14\MSACC.OLB" .AddFromFile " C:\Windows\SysWOW64\stdole2.tlb"
AddFromFile FromFile " C:\Program Files (x86)\Common Files\Microsoft
Shared\OFFICE14\ACEDAO.DLL" .AddFromFile " C:\Program Files (x86)\Common
Files\Microsoft Shared\VBA\VBA6\VBE6EXT.OLB" .AddFromFile " C:\Program Files
(x86)\Common Files\Microsoft Shared\OFFICE14\MSO.DLL" End With
' Call a hidden SysCmd to automatically compile/save all modules.
'Call SysCmd(504, 16483)
'RunCommand mand acCmdCompileAndSaveAllModules ' May fail, but so what
End Sub