fat controller
Slightly round the bend..
- Local time
- Today, 00:11
- Joined
- Apr 14, 2011
- Messages
- 758
I am curious now - I currently don't have the OnAction against any of them, so they are not calling on any functions, but it is working fine??
Option Compare Database
Option Explicit
Public Sub fixReference()
Dim ref As Access.Reference
Dim strFullPath As String
Dim strFile As String
Dim lngPos As Long
For Each ref In Access.References
If ref.IsBroken Then
strFullPath = ref.FullPath
' check if one of missing is MS Office Lib
lngPos = InStrRev(strFullPath, "OFFICE")
If lngPos <> 0 Then
' if this is Office Lib, remove the reference
Access.References.Remove ref
' separate the file from the path
strFile = Mid(strFullPath, InStrRev(strFullPath, "\") + 1)
'below is the path
strFullPath = Left(strFullPath, Len(strFullPath) - Len(strFile))
'remove the word "OFFICE" from the path
'and replace it with Local Version installed
strFullPath = Left(strFullPath, lngPos - 1) & "OFFICE" & Int(version()) & "\" & strFile
'add reference to this version
Access.References.AddFromFile (strFullPath)
End If
End If
Next
End Sub
Public [COLOR="Red"]Function[/COLOR] FixReference()
Dim ref As Access.Reference
Dim strFullPath As String
Dim strFile As String
Dim lngPos As Long
For Each ref In Access.References
[COLOR="red"] If ref.Name = "Office" Then[/COLOR]
If ref.IsBroken Then
strFullPath = ref.FullPath
' check if one of missing is MS Office Lib
lngPos = InStrRev(strFullPath, "OFFICE")
If lngPos > 0 Then
' if this is Office Lib, remove the reference
Access.References.Remove ref
' separate the file from the path
strFile = Mid(strFullPath, InStrRev(strFullPath, "\") + 1)
'below is the path
strFullPath = Left(strFullPath, Len(strFullPath) - Len(strFile))
'remove the word "OFFICE" from the path
'and replace it with Local Version installed
strFullPath = Left(strFullPath, lngPos - 1) & "OFFICE" & Int(Version()) & "\" & strFile
'add reference to this version
Access.References.AddFromFile (strFullPath)
End If
[COLOR="red"]If lngPos > 0 Then
'set the boolean flag = true so the function won't run in future
CurrentDb.Execute "UPDATE tblAppSettings SET tblAppSettings.OfficeRefCheck = True;"
End If[/COLOR]
[COLOR="red"]Else
'set the boolean flag = true so the function won't run in future
CurrentDb.Execute "UPDATE tblAppSettings SET tblAppSettings.OfficeRefCheck = True;"[/COLOR]
End If
[COLOR="Red"]End If[/COLOR]
Next
End Function
I have a database that when deployed will be used mainly via the Access Runtime environment, and therefore the features to export reports to Excel, Word etc will not be available.
In the past, I have used a custom shortcut menu, code as follows:
So, I thought I had nothing more to do than pinch that code, and use it in the new database...... initially, I got a runtime error (object not defined) with the line Dim CB as CommandBar hightlighted.Code:Dim MenuName As String Dim CB As CommandBar Dim CBB As CommandBarButton MenuName = "vbaShortcutMenu" On Error Resume Next Application.CommandBars(MenuName).Delete On Error GoTo 0 Set CB = Application.CommandBars.Add(MenuName, msoBarPopup, False, False) Set CBB = CB.Controls.Add(msoControlButton, 19, , , True) CBB.Caption = "Copy..." CBB.FaceId = 19 Set CBB = CB.Controls.Add(msoControlButton, 22, , , True) CBB.Caption = "Paste..." CBB.FaceId = 1436 Set CBB = CB.Controls.Add(msoControlButton, 11725, , , True) CBB.Caption = "Export to Word..." CBB.FaceId = 42 Set CBB = CB.Controls.Add(msoControlButton, 11723, , , True) CBB.Caption = "Export to Excel…" CBB.FaceId = 263 Set CBB = CB.Controls.Add(msoControlButton, 12499, , , True) CBB.Caption = "Save as PDF…" CBB.FaceId = 3 Set CB = Nothing Set CBB = Nothing End Sub
I added in Microsoft Office 15 Objects as a reference, and thereafter the code compiled fine - however, it does not appear to work.
I have stepped into the code, and it runs through as though it is doing its thing, but when I right click on the report in Preview, I get the 'normal' shortcut menu.
Any ideas?
Excellent suggestion. I do have a question, it seems that I have to do the F5 every time I log in to the database. Is there a way so I do not have to do F5 each time I log in?you don't call it on the Report/Form load. and you don't need to
you put the code in standard module.
if you need to add new item for menu edit the sub and run it (F5).
once the shortcutmenu is created it becomes part of your database
so no need to re-run and re-create it again and again.
it is available on all reports/form, put you must explicitly
put it in its Property on design view, just like you did today.
Hi. Welcome to AWF!Excellent suggestion. I do have a question, it seems that I have to do the F5 every time I log in to the database. Is there a way so I do not have to do F5 each time I log in?