Since the most recent security update for Outlook my code won't run. Using Outlook 2010. Have a contact form with custom code behind. I click a custom button to open a post item in the History folder. The post item has custom code behind it to write information to a text file. Very important for this to run. Since a few days ago the code on the post item doesn't run anymore. But if I save the post item, close it and reopen it the code runs fine. What is happening and how do I fix it?
'this is the code on the contact form
Sub CallFromButton
'get the folder
Dim HistFolder
Set HistFolder = Application.Session.GetDefaultFolder(18).Folders("History")
'add a post item
Dim blgItem 'PostItem
Set blgItem = HistFolder.Items.Add("IPM.Post.ClientHistory2")
'set some information
blgItem.BillingInformation = "60000"
blgItem.UserProperties("ClientName") = item.FullName
blgItem.UserProperties("blgDate") = Now
blgItem.Display
'... more code
End Sub
'this is the code behind the post item
Sub Item_Open()
Dim LogPage
Set LogPage = Item.GetInspector.ModifiedFormPages("Log Item")
LogPage.Controls("ResumeBtn").Visible = False
LogPage.Controls("BoxDesc").SetFocus
Item.UserProperties("blgFileName") = "C:\Temp\12345.txt"
'... more code
End Sub
Function Item_Write()
'... more code
End Function
A recent Windows update caused this. You can either uninstall it, or wait for a fix from Microsoft: https://social.technet.microsoft.com/Forums/office/en-US/e6147cb8-fe1c-4d90-a65a-33b8a7b22a6d/june-security-patch-and-issue-with-custom-forms?forum=outlook
Related
I'm trying to create a add in for MS Word with VBA.
It has a "AutoExec" procedure that creates a new item in the CommandBar("Text") collection (right click menu) and a "AutoExit" that deletes this created item.
As an example, I tried the code below that create an item "How Many Pages?", which executes a macro displaying the number of pages in the active document.
This is the AutoExec Code:
Public Sub AutoExec()
Dim objcommandbutton As CommandBarButton
Call MsgBox("AutoExec")
Set objcommandbutton = Application.CommandBars("Text").Controls.Add _
(Type:=msoControlButton, Before:=1)
objcommandbutton.Caption = "How Many Pages?"
objcommandbutton.OnAction = "HowManyPages"
End Sub
This is the AutoExit Code:
Public Sub AutoExit()
Dim objcommandbutton As CommandBarControl
Call MsgBox("AutoExit")
For Each objcommandbutton In Application.CommandBars("Text").Controls
If objcommandbutton.Caption = "How Many Pages?" Then
objcommandbutton.Delete
End If
Next objcommandbutton
End Sub
This is the Main Macro Code:
Public Sub HowManyPages()
If Documents.Count > 0 Then
Call MsgBox(ActiveDocument.BuiltInDocumentProperties("Number of Pages"))
Else
Call MsgBox("No document is currently active.")
End If
End Sub
When exiting the document, the Button previously added in CommandBars("Text") collection is not deleted. I see this when I open a new blank Word document and the button remains in the right click menu.
I know that the routine is performed correctly because there is a MsgBox instruction to verify it.
This only happen with the AutoExit subroutine of a add-in, that is, loaded as a add-in: running the code in a macro with vba module works fine.
Any help?
When working with the CommandBars object model in Word it's necessary to always specify the Application.CustomizationContext.
Word can save keyboard layouts and CommandBar customizations in various places: the Normal.dotm template, the current template or the current document. The default when you create a CommandBar addition may not be the3 same as the default when trying to delete something.
Since this is an add-in, I assume you want the change for the entire Word environment (any open document). In that case, use the context NormalTemplate. Use this before any calls to CommandBar:
Application.CustomizationContext = NormalTemplate
Note: for saving a customization in the current document: = ActiveDocument; for saving in the template attached to the current document: = ActiveDocument.AttachedTemplate.
I solved my problem with a workaround:
I was trying to "add" a template (.dotm) as a add-in (in the "Templates and Add-ins" window) to use my VBA project in a new document. That's why I was using the AutoExec() and AutoExit() procedures.
But only now I figure out that just "attaching" the .dotm template to the active document (in the same "Templates and Add-ins" window, as show in the figure below) makes the functions Private Sub Document_Open() and Private Sub Document_Close() to run normally. Which solves my problem.
Even so, I think there is a certain "issue" with the AutoExit() procedure when trying to change the CommandBars itens. But that's ok for now.
enter image description here
My goal is to create a VB application that reads and writes information to various webpages loaded in Internet explorer.
I have created a program that works exactly as I intend in VBA. I am now trying to re-implement the same programming in VB.
I have a function that looks for and returns an Internet Explorer Object where the input matches the LocationName.
Assuming the target page is loaded, I can work with it. Methods such as getElementByID() work perfectly. If the browser window is closed and reopened, and the code is run again, the results are very inconsistent. The getIE function seems to work, but when trying to use methods like document.getElementByID() a NullReferenceException is thrown.
Does anyone know if there is anything I am missing that I need to include to get the document property to update?
EDIT: I have looked over the NullReferenceException article. It hasn't helped me unfortunately. In case I was unclear in my wording, I would like to reiterate that the same bit of code yields a different result when executed the 2nd time under the same conditions (same webpage open in Internet Explorer).
On the second execution IE.locationName is retrievable but IE.Document.title is not. The problem is definitely with the Document property as far as I can tell. I am truly stumped.
Many thanks
Public Function getIE(targetTitle As String) As SHDocVw.InternetExplorer
' Create the shell application and Collection of open windows
Dim shellObj As Object = CreateObject("Shell.Application")
Dim shellWindows As SHDocVw.ShellWindows = shellObj.Windows()
getIE = Nothing
' Scan through the Collection
For I = (shellObj.Windows.Count - 1) To 0 Step -1
' If found, assign this to the function output and exit early
If InStr(shellWindows(I).LocationName, targetTitle) Then
getIE = shellWindows(I)
Debug.Print("Found: " & shellWindows(I).LocationName)
Exit For
End If
Next I
End Function
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim IE As SHDocVw.InternetExplorer
IE = getIE("my site title")
If IE Is Nothing Then
Debug.Print("Site not open")
Exit Sub
End If
' The code always gets this far, and despite the page being found, starts throwing exceptions from here on if the window has been closed and reopened whilst my application has stayed running.
' Sample form data insertion code
IE.Document.getElementById("textbox1").value = "my value"
' Click the submit button
IE.Document.getElementById("submit").click()
' Wait for page to load
While IE.Busy
End While
IE.Document.getElementById("textbox2").value = "my 2nd value"
' done
IE = Nothing
End sub
I am building an Access report (2010 version), and would like to be able to customize it based on the user's selections on a form. When I run it, I get error 2771: The bound or unbound object frame you tried to edit does not contain an OLE object.
This is the code to pass the parameter:
Private Sub Command120_Click()
DoCmd.OpenReport ReportName:="rpt_EODGraph", View:=acViewPreview, _
OpenArgs:=Me!Text0.Value
End Sub
This is the code to open the report.
Private Sub Report_Open(Cancel As Integer)
Dim ch As Chart
Set ch = Me.Graph3.Object.Application.Chart 'This line generates the error
ch.ChartTitle.text = OpenArgs
End Sub
I've found at least one person saying that this is not actually possible to do on a report. (http://www.access-programmers.co.uk/forums/showthread.php?t=177778&page=2 Note that this is page 2 of a 2 page forum discussion...) Can anyone corroborate or refute?
Apparently the Report has to have some kind of focus before OLE objects are accessible.
It is enough if you click on it or set the focus to something:
Private Sub Report_Open(Cancel As Integer)
Dim ch As Object
Me.RandomButton.SetFocus
Set ch = Me.Diagramm11.Object
ch.ChartTitle.Text = "Hello"
End Sub
This works. I just set a button on the report that gets the focus. Perhaps you find something more elegant ;)
I've inherited a Access database that is used to import some data in SQL. The MDB opens with a form, in a modal mode: no Access menubar or buttons are visible. I can view the tables with content by using the Visual Studio 'Data Connection' tool, but I cannot see the module's code.
I've looked at this question here, but the answers there aren't really what I need. Is there a way to either force the form to close (and access the modules) or to extract the VBA code ?
[EDIT] I am using Access 2007, not sure what the original developer used.
Hold down the shift key when you open the database. This will prevent it from loading the automatic script it's running and allow you to gain access to the tables, queries, and VBA scripts.
This is a rather long addendum to, or comment on, Michael Todd's reply in response to edosoft's comment.
Rather than choosing to enable the content, check the start-up options (either (file->options->current database->display form) or (tools->start up->display form)) and remove the name of the form, having taken a note, and ensure that Allow Full Menus (same page) is ticked. You may also like to press Alt+F11 to display code, and check that for start-up code, finally, see if there is an AutoRun macro and rename it.
EDIT re Comments
You do not have to open an mdb to change the start-up form, for example, code such as this could be run from another mdb using the full name and path of the mdb you wish to change.
Sub SetStartForm(DBFile As String)
Dim prp As Object
Dim db As Database
Const PROPERTY_NOT_FOUND As Integer = 3270
Set db = OpenDatabase(DBFile)
db.Properties("StartupForm") = "(none)"
If Err.Number > 0 Then
If Err.Number = PROPERTY_NOT_FOUND Then
'' Create the new property, but this is not relevant in this case
End If
End If
db.Close
Set db = Nothing
Set prp = Nothing
End Sub
Button close with function:
Private sub cmdClose_Click()
CloseForm(YourFormName)
End sub
Public Sub CloseForm(ByVal strFormName As String)
Dim iCounter As Integer
For Each frm In Forms
With frm
If (.Name = strFormName) Then
iCounter = iCounter + 1
End If
End With
Next
If (iCounter > 0) Then
For i = 1 To iCounter
DoCmd.Close acForm, strFormName, acSaveNo
Next
End If
End Sub
I'm working on a Domino Client application that opens documents up in a frameset.
When I click the save button it does some lotus script validation, adds to history field and etc then finally does a save:
Sub Click(Source As Button)
Dim validate1 As Validation
Dim ws As New NotesUIworkspace
Dim s As New NotesSession
Dim uidoc As NotesUIDocument
Dim approverNames As String
Dim workflow1 As Workflow
Dim name1 As String
Dim names1 As String
Dim item1 As NotesItem
Dim history1 As History
Set uidoc = ws.CurrentDocument
Call uidoc.refresh
'===============================================
'Validation
'===============================================
Set validate1 = New Validation()
Call validate1.checkCustomer(uidoc.FieldGetText("Customer"))
Call validate1.checkEndUser(uidoc.FieldGetText("EndUser"))
Call validate1.checkShortProjectDescription(uidoc.FieldGetText("ShortProjectDescription"))
Call validate1.checkProjectName(uidoc.FieldGetText("ProjectName"))
Call validate1.checkProjectLocation(uidoc.FieldGetText("ProjectLocation"))
Call validate1.checkOperationCenter(uidoc.FieldGetText("BusinessUnit"))
Call validate1.checkSalesCenter(uidoc.FieldGetText("SalesCenter"))
Call validate1.checkMarketSegment(uidoc.FieldGetText("MarketSegment"))
Call validate1.checkSAPDate(uidoc.FieldGetText("SAPDate"))
Call validate1.checkRevision(uidoc.FieldGetText("Revision"))
Call validate1.checkValidityDate(uidoc.FieldGetText("ValidityDate"))
Call validate1.checkDateApproval(uidoc.FieldGetText("DateApproval"))
Call validate1.checkCurrencyUSD(uidoc.FieldGetText("CurrencyUSD"))
Call validate1.checkMargin(uidoc.FieldGetText("Margin"))
If validate1.displayErrorMessages() = 0 Then
'========================================================================
Call uidoc.FieldSetText("WhoHasApproved","")
Call uidoc.FieldSetText("ApproversNotified","")
Call uidoc.FieldSetText("SubmitDate",Cstr(Now))
Call uidoc.FieldSetText("Status","In Process")
'Add calls to workflow here....
Set workflow1 = New workflow("SAPFCD")
'Update History Field - Submitted for Processing by
Set history1 = New History(uidoc.Document)
Call history1.addTo("Submitted for Processing", uidoc.FieldGetText("CreatedBy"))
Set item1 = uidoc.Document.ReplaceItemValue("History" , history1.getDescription())
'Set ApproverList
names1 = workflow1.setApproverList(uidoc)
Call uidoc.FieldSetText("ApproverList",names1)
uidoc.Refresh
name1 = workflow1.setNextApprover(uidoc)
Call uidoc.FieldSetText("NextApprover", name1)
'========================================================================
'Add calls to workflow here....
Call uidoc.FieldSetText("Status","1st Peer")
uidoc.Save
uidoc.Close(True)
uidoc.Close(True)
End If
End Sub
and then proceeds to close the entire database and returns user to workspace.
What I want is to have the document saved and then return the user to a specified page in the frame set.
I attempted to add code like this to the QuerySave event, but does not work:
Sub Queryclose(Source As Notesuidocument, Continue As Variant)
Dim ws As New NotesUIworkspace
ws.OpenFrameSet("MainFrame")
ws.SetTargetFrame("Main")
ws.OpenPage("Saved")
End Sub
Any ideas on how I can save/close a UI document that is in a frame set without it closing the entire database.
Derek
Any specific reason why you have the document open within a frame of a frameset?
Usually you have a frameset for the outline and view and documents open on their own tab/window, this way when the code you have runs it only closes the doc.
**Update
Did some more testing and you can insert this after the uidoc.save and remove uidoc.close
Call ws.SetTargetFrame("your frame name here")
Call ws.ComposeDocument("","","your form name here",,,False)
I forgot to mention you should set the target frame back to "" when exiting the app, if you don't users might get error when other apps try to open up a frameset.
It should work fine if you only include one uidoc.close event instead of the two you have showing.
Also make sure none of the Form events PostSave/PostClose or QuerySave/QueryClose call a close event.