How can I change the Chart Title in an Access report with VBA? - vba

I have an Access Report with a chart and I want to change the title of the chart when the report is opened (preview or print).
I found the following code:
Dim g As Graph.Chart
Set g = Me!Graph0.Object
With g
.ChartTitle.Text = "Test"
End With
But I don't know with which event I should run this code. I tried Report_Open and other events but it never changes the title.

I am not sure if your code works, but to trigger an event on opening a report you need to put the code into the Report.Load event.
Check out msdn: https://msdn.microsoft.com/en-us/library/office/ff197739.aspx

I found the answer here:
Modify Chart properties in Access report via VBA (error 2771)
First I copied the chart from a report to a form and tested the code to change the title. That worked.
Then I tried to run the code with the open or load event in the report and I always received an error. I googled that error and found the article above and that was the solution.
I just added a button to the report and added the line
Me.Command1.SetFocus
at the beginning of my code.
Now I can run the code from Report_Load() or Report_Open(). It works for both.
Problem solved.

Use the OnActivate event if using a Form.

Related

Run-Time Error 4605: The ShowHiddenText method or property is not available because this command is not available for reading

I'm fairly new to using content controls and I'm designing a Word form for work. The current form has the help text for content controls hidden (I have the option enabled to display hidden controls on my computer); however, I want to make sure users of the form are able to see these controls when they open the form. The issue is that when the help text is not hidden, it prints on the form. Is there a way to set the controls so the help text does not print but it is still visible to users when they open the form?
I tried using the following code, but I ran into issues with it. The code worked on my computer, but when a coworker tested it it caused an error message to appear and I could not figure out why. The single line of code was highlighted but as the code worked on my computer, I'm not sure how to fix it (I am also very new to Visual Basic).
Sub AutoOpen()
ActiveWindow.View.ShowHiddenText = True
End Sub
I was hoping that when another user opened the document, they would see the hidden text as if it were not hidden; however, when another user opens the document, they get this error:
"Run-time error '4605':
The ShowHiddenText method or property is not available because this
command is not available for reading."
The error message is happening because Word is opening the document in the Reading rather than the Print view. That is often the case when a document is opened from email, for example.
Adding the following line before the line for hidden text should help, as it will force the document to switch to the Print Layout view:
ActiveWindow.View = wdPrintView
So
Sub AutoOpen()
Dim vw as View
Set vw= ActiveWindow.View
vw = wdPrintView
vw.ShowHiddenText = True
End Sub

MS Access VBA - Retain changes made to a report's size/control sizes while in Layout View

I have the following (simplified) VBA code that demonstrates the problem while resizing a report and its controls from a module. To reproduce, create a new blank database, add a table and a report, then add this code into a new module:
Public Sub ResizeReport()
Dim rr as Report
Dim cc as Control
Set rr = Screen.ActiveReport
For Each cc in rr.Controls
cc.Width = 1 * 1440
Next
rr.Width = 5 * 1440
End Sub
If I open a report in Design View and run the macro, the changes stay when I change to other views (such as Report View, Layout View, or Print Preview). However, if I open the report in Layout View and run the macro, the report and its controls are resized, but as soon as I change the view mode, the report reverts to its state before the resize.
Please note that this issue does not occur if I manually resize the report/controls using drag handles or the Property Sheet while in Layout View.
Is there a command I need to issue after resizing the report/controls from VBA while in Layout View to get the changes to stick? Or should I be resizing the report/controls using different VBA commands?
I am using MS Access 2010.
Thank you for the short yet detailed question and functioning "MCVExample". I may need to refer other newbies to this question as an example of a perfect question. +1 for that even though the answer seems obvious. :)
You should save the report before changing it's view.
DoCmd.Save acReport, rr.Name
This will force the changes to "stick". The logic behind the report reverting to its previous state when changing view is to allow for dynamic, temporary changes at runtime, without permanently affecting the report.
More Information:
MSDN : DoCmd.Save Method (Access)
MSDN : Set Form, Report, and Control Properties in Code

How to open object(macros) and use the form in it using command button?

Hi GUYS , I will explain my problem:
1- I use object command in excel to bring another excel file see image(1)object_image
2- I want to make command button which links to the object
3-image (2) show the worksheets and forms note when I close the book, the object's book change image all
so what I want is when I click the command button in my first excel it will open the form and allow me to change in the second excel.
this is my code
Private Sub CO1_Click()
Workbooks("Book3").Worksheets("Sheet1").CommandButton1.Value = True
Application.Run Workbooks("Book3").Worksheets("Sheet1").OnAction
trainUserForm.Show
End Sub
please, guys, i need this to finish my work and thx :)

How do I use TextChanged event in VBA visio?

This is related to this question
How do I programmatically/automatically change the text formatting for the text of a Visio shape after I am done with the editing?
There I tried to use some code that would be executed when the text of a shape is edited
For some reasons, as described there, in some situations which I could not isolate the code is executed endlessly.
That is probably because the script calls itself in a loop. The code is supposed to be executed every time the text of the shape is edited BUT the code itself changes the color of the text. I guess that would count as a new text change and so on.
I am thinking about using the event called TextChanged. According with the documentation this should execute the code when the user finished the editing
http://msdn.microsoft.com/en-us/library/office/ff768749.aspx
I could not find a example of using such event in VBA and here is where I need your help
thanks in advance
Uni
This is how I tested:
I used CallThis('ThisDocument.warning") to call the procedure below from "TheText" event of that shape (available via the shapesheet)
Sub warning(oShape As Visio.Shape)
MsgBox ("Text edited")
End Sub
This gets executed like three times if I star editing the text of a shape and I press the space key (adding a space to the existing text)
Ok here is how you do it:
Open the Code editor
In the Project explorer select "ThisDocument"
Next in the ObjectWindow select Document
Then in the Method dropdown box select ShapeExitedTextEdit
You will see a skeleton procedure like below
Private Sub Document_ShapeExitedTextEdit(ByVal oShape As IVShape)
End Sub
There is where you add the code that you want to be executed every time when the editing if finished

Access 2010 Me.Refresh/Me.Requery

I have a form that I want refreshed when the submit button is clicked. Preferably those that have default values will be restored and those without will be blank.
The submit button has an attached OnClick Macro that, checks to make sure all fields are filled, if so an action query runs that inserts a new row into a table.
So its after this action query that I want the refresh to occur. I have tried researching and come across suggestions that suggest using VBA code Me.Requery or Me.Refresh. I'm not 100% on how to incorporate this into the macro. The RunCode command doesn't recognize the function I put the code in, and The convert macro to VBA option in the top left is grey'd out.
I'm new to Access and just not seeing where the communications are for code and macros if someone could please elaborate for me I would be greatly appreciated.
Please consider my solution as a brief introduction to VBA. If you care to learn the language, you will find there is very little you cannot do.
Within your submit button properties, there should be an 'Event' tab. In this tab, the On Click should be set to [Event Procedure]. Click the three dot button just to the right of that, and it will launch the VBA editor.
All you need to have here between the Private Sub and End Sub lines are these lines of code:
DoCmd.RunMacro ("Mac_1")
Me.TextBox1.Value = "Null"
Me.CombBox1.Value = "Null"
Me.Refresh
MsgBox "Your Save Was Successful.", vbOKOnly, "Saved"
"Mac_1" is the name of the macro you want to execute. the ME.Refresh executes as soon as mac_1 finishes, and will refresh the page. Be sure to enclose it in a proper quote (") and not a double tick ('').
The Requery command can be used from both within VBA code or a macro. It sounds like you are using the macro designer so you can use the Requery macro action instead of VBA.
Just add this to your macro after you have inserted your new data.
This macro action lets you specify a control to requery. The parameter can be left blank to requery the source of the active object. More information can be found here.
Edit
In response to your comments, I think you should try experimenting with the SetProperty macro action (more details here).
I have attached this macro to a button click event and the value from the TextBox called txtInputValue is cleared. The Value field is left blank as you want to fully remove the value from the text box.