Change the color of a selected record in an Access REPORT - vba

My Access REPORT has a text box with the Record ID that looks like a button with an on click event to go to a form for that specific record. This works great, but when I return to the report I cannot see which record was clicked. I want to temporarily change ONLY the record that was clicked until another record is selected.
The reason I want this on a report and not a form is because I want the user to have a quick way to proof read in the format needed to print, and make a change or check a detail if necessary, then update the report AFTER all proof reading and updates are completed and before final print. But with many records on the screen it is easy to lose track of which record you were checking when returning from the form.
I tried:
Private Sub btn_txt_GoToTransaction_Click()
Dim vColor
vColor = RGB(51, 204, 51) 'green
Me.btn_txt_GoToTransaction.BackColor = vColor
DoCmd.OpenForm "Account_frm", acNormal, , "[TransactionID]=" & Me.TransactionID
End Sub
But this does not work because every button turns color not just the selected record.
Any suggestions? Thanks.

This is a great question because there are many benefits to highlighting a row or item in an Access Report. You are not able to just change the button color in one row only, but you can highlight the whole row so the user knows where they were.
Here are two methods to accomplish this:
Method 1 - Click on a Label
This works great in newer versions of MS Access when using Report View. Use a Label Control instead of a Button. You could make the label look like a button if you format it that way. I prefer to stretch an invisible Label across the whole row on top of all the other controls in that row. Then if you click anywhere in the row, it automatically selects that row and then runs whatever code you have in the OnClick Event. This works best if the Label is not linked to a Text Box.
This picture shows an example of how this method looks. You can click anywhere in the row and it highlights that row with the red outline and grey background.
This is very simple and works well but there are a couple disadvantages:
1- You can not change the color of the highlight.
2- If any of the text boxes CanGrow, the row height may be higher then the Label and create areas where the invisible label doesn't capture your click.
3- Clicking on a Text box does not work for this method.
Method 2 - Change Color of a Text Box
In order to just highlight one row or one piece of data in a report, we can use the "FormatConditions" property. This is the same as Conditional Formating from the MS Access design interface but we are going to change it programmatically on the fly. You can't do this with a button or label - it needs to be a Text Box with unique data, such as your TransactionID.
This picture shows an example of how this method looks. You can set the color of the highlight if you follow the steps below.
STEP 1) I recommend that you add a text box to your report that stretches from the left to the right, set the Back Color and Fore Color to White, set the Control Source to TransactionID, and set the Name to TransactionID. Then right click on this text box and select Position > Send To Back. This works best if the other text boxes and labels on the report have a transparent background.
STEP 2) Add this code:
Private Sub HightlightRow(intRowID As Integer)
With Me.TransactionID.FormatConditions
.Delete
With .Add(acFieldValue, acEqual, intRowID)
.BackColor = vbGreen
.ForeColor = vbGreen
End With
End With
End Sub
STEP 3) Also change your button code to call this subroutine like this:
Private Sub btn_txt_GoToTransaction_Click()
HightlightRow Me.TransactionID.Value
DoCmd.OpenForm "Account_frm", acNormal, , "[TransactionID]=" & Me.TransactionID
End Sub
STEP 4) I like to set it up so if the user clicks anywhere in the row, it will pop up with a modal with more detail regarding that row. Also, the user can't make any changes to the data in the Report View, so I use the pop up modal to allow changes. To accomplish this, I do a couple more things:
First, we need to add the code to the OnClick event for every control in that row. Ofcourse, each OnClick event will simply can that subroutine HightlightRow Me.TransactionID.Value
Second, if the user clicks on a Text Box, the Text Box gets the focus and hides the highlight. Therefore, I like to set the focus to something else. In your case, you could set the focus to the button by adding this line to the end of the HighlightRow subroutine: btn_txt_GoToTransaction.SetFocus
In my case, I am not using a button, so I set up a tiny Text Box with = " " (just an equal sign a space in quotation marks) as the Control Source. Then I position this tiny Text Box to the far right. And in the HighlightRow subroutine, I set the focus to this textbox.
STEP 5) You may also want a button or method of removing the highlight. To do that simply have the code run this line:
Me.TransactionID.FormatConditions.Delete

Related

How to arrange bookmarks individually with Range.InsertBefore method or with other options

I am facing the following problem:
In my Word document there are about 30 checkboxes with text behind them, which can be selected if needed. If you click on a checkbox, the text next to the checkbox appears at the bottom. This is done with:
Private Sub CheckBox63_Click()
Dim BM63 As Range
Set BM63 = ActiveDocument.Bookmarks("BM63").Range
BM63.Text = "6.3. Datenprüfung, Gewichtung" & vbNewLine
End Sub
All 30 bookmarks are entered in the same place. So all texts appear at the same position separated by a paragraph. But now the first clicked points are at the bottom, because the other points move up piece by piece.
But I want the last checkbox clicked to be at the bottom and the first at the top.
I tried it with the Range.InsertBefore method but couldn't get it to work.
Does anyone have a solution?
Thanks:)

Macro in form stops working after opened with vba

Please help me explain, why this happens, after that the solution should be easy :)
I have two forms, showing different data.
Form_1: there is a combo box (with names in it), where you can choose which company you wanna see, and an after-update macro searches the record (an [ID] field), and shows the information. (To be more complicated, this [ID] field is hidden, and used for subforms, where the actual infos appear.)
Form_2: this is a continuous form, each record is in connection with the companies shown in Form_1, but several record can belong to one company. There is a button for every record to open Form_1 with the information connected to it. The vba code of the button is:
Private Sub Button_Click()
DoCmd.OpenForm "Form_1", , , "[ID] = " & Me![ID]
End Sub
In the code, the same [ID] field is used, as described above: hidden and used for subforms.
Both forms are working as needed, I am happy with them.
But after Form_1 is opened from Form_2 with the button, the combo box remains empty (actually I don't need it to be filled), and if I wanna use it to search for other items, it doesn't work, as if the macro wasn't loaded. The list of names appear, I can click on any of them, but the [ID] field is not refreshed (and of course neither the subforms). I have to close the form, and open it again from the side-list.
Why does the macro stop working?
What should I change, to make it work?
Thanks for your help!
Form1 has the filter turned on to a specific key value, so attempts to find and reposition the form's current record will fail without explicitly resetting the filter.
The Where condition of the OpenForm command does not change the form's Record Source property, nor does it perform a simple search/reposition. Rather, it applies a form filter:
DoCmd.OpenForm "Form_1", , , "[ID] = " & Me![ID]
This state is indicated in several ways
On the Home ribbon (i.e. toolbar): The Toggle Filter button is active... is highlighted by a different color.
The form's navigation bar at the bottom of the form show "Filtered" highlighted with a little funnel icon.
The Access status bar shows "Filtered" on the right near other indicators.
Of course it's possible that all of those indicators are hidden, so you just need to be aware of what each command and parameter does.
Possible solutions:
Form1's ComboBox.AfterUpdate macro should turn off the filter before searching for a new ID value.
Form2's Button_Click event opens the form without applying a filter and instead runs code that does the same thing as the ComboBox.AfterUpdate method--searches and repositions the form's record rather than filtering it.
This can be achieved in multiple ways and is largely beyond the scope of this answer, but a hint is to make a Public method in the Form1 module that performs the search. Both the ComboBox.AfterUpdate method and the other button call that same public method so they have the same behavior.

How to show/hide data from a table in Powerpoint?

I'm trying to have several slides with tables, each table has 3 columns, the last column is the "reference value" and I want it to be hidden during the presentation and show it only by pressing a button or a hyperlink, each row individually. I think it's possible because I'm really new at coding and I have managed to do it by changing the cell's text format from white (which is the table's background color) to red, but I can only do it for all the tables at once, and I need individual values on each one of them. (I hope I'm making myself clear). This is what I have done so far:
Sub format()
Dim s As Slide
Dim oSh As Shape
Dim oTbl As Table
For Each s In ActivePresentation.Slides
For Each oSh In s.Shapes
If oSh.HasTable Then
Set oTbl = oSh.Table
With oTbl.Cell(2, 3).Shape.TextFrame.TextRange
.Text = "4500-9000"
.Font.Size = 12
.Font.Color = vbRed
End With
End If
Next
Next s
End Sub
But this will change the same cell on every table I have, I want it to change specific cells in specific tables one by one, since they all have different valued. I know I could do this with animations, but I'd rather do it this way.
EDIT: It would be great if, instead of pressing a button, I could get the data by hovering the pointer over the empty cell, and have it hidden away again when I hover the cursor off the cell.
In any case, whenever I do any change to the presentation during slideshow, the change will still be there at the end, which means It would only work once and then I would have to fix and hide all the values again, is there a way to restore the changes done during the presentation when it ends?
you could adpt your sub and call it from another procedure by passing a reference to the table and cell you want to process like this:
Sub FormatTableCell(oTbl As Shape, lRow As Long, lCol As Long)
With oTbl.Cell(lRow, lCol).Shape.TextFrame.TextRange
.Text = "4500-9000"
.Font.Size = 12
.Font.Color = vbRed
End With
End Sub
For example:
With ActivePresentation
FormatTableCell .Slides(1).Shapes("MyTable"), lRow:=1, lCol:=1
End With
Regarding the triggers for hover over and hover out, this is a tricky aspect of PowerPoint. There IS a trigger to run code when hovering over a shape but there is NOT a trigger for hovering out of a shape. To achieve the latter, you could put a transparent rectangle in the back layer of your slide and use that to spoof the hover out trigger by linking a hover over macro to it. Write your code and use the Insert / Action / Mouse Over function to trigger your VBA procedure with a signature like this:
Public Sub FormatThisTable(oTbl As Shape)
Note that this method only passes the shape (a table in your case) and not the cell the mouse is hovering over. The only way I can see you could achieve that would be to use a lot of very complex Windows APIs to detect the mouse cursor position relative to the table's on-screen coordinates.
Alternative approaches could either be to ungroup the table to a set of separate shapes or create cover shapes for each cell you need to show/hide and manage their visibility properties using the mouse in/out technique above.
For the last point, you will need to use application level events which requires code in a class module and this a good article to show you how:
http://www.pptfaq.com/FAQ00004_Make_your_VBA_code_in_PowerPoint_respond_to_events.htm
Step 1
Launch PowerPoint and open the PPTX file that contains the rows you want to hide. Click the appropriate slide in the Slides pane to the left of the screen.
Step 2
Double-click the spreadsheet on the slide, which will allow you to edit it. Select the rows that you want to hide. Click the “Home” tab and locate the “Cells” section. Click the “Format” option, which will display a list of available features.
Step 3
Place the pointer over the “Hide & Unhide” listing in the “Visibility” section. Click the “Hide Rows” option to hide the selected rows. Click outside the spreadsheet to return to the PowerPoint slide.

Microsoft Word VBA tab key to make textbox visible

Longtime viewer, first time question asker.
I'm currently working with UserForms within MS Word and have a particular form that can have up to 20 different labels and accompanying textboxes with varying texts. I have all but the first hidden while not in use, however I would like the next label and text box to become visible following input in the previous textbox. So if you enter data (anything) in the first textbox, the next label and text box will become visible. Does this make sense? I've seen other responses here suggest using AfterUpdate() rather than Change() or Click() but can't figure out how to use any of them. I would share my code but at this point I don't have any code to share, other than my labels and textboxes are lblField1 txtField1, lblField2 txtField2...
Any suggestions?
I would suggest using Change event, when using AfterUpdate you need to leave you TextBox for a while to fire the event. If you have only one TextBox visible there is nothing to move to. If you have more TextBoxes you would need to move back to fire AfterEvent and I don't think this is what you expect.
So, double click wherever on your userform and add the following code in code area:
Private Sub txtField1_Change()
txtField2.Visible = True
lblField2.Visible = True
End Sub
Next, add next portion for next textbox:
Private Sub txtField2_Change()
txtField3.Visible = True
lblField3.Visible = True
End Sub
And so on, if only you have an order in controls name you just need to change numbers in the end of control names.

How to wrap comment.text in vba

I have a situation in which text in one of the cells is massive.When I change the contents of this cell the previous value becomes a comment to that cell.Now the problem is, this text is so big that I cannot see complete text.If I use .Shape.Textframe.Autosize=true then I have to go on browsing till god knows when to see the text.
What I need to do is whatever and however big the text might be in Commnet.text,I want to show it in one and one place only.i.e when I hover on comment.
Place a TextBox where you will on your worksheet adjusted to the size you want, this still reads the comment although this is not on a hover, but perhaps will help
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not ActiveCell.Comment Is Nothing Then
ActiveSheet.Shapes("Text Box 1").TextFrame.Characters.Text = ActiveCell.Comment.Text
Else: ActiveSheet.Shapes("Text Box 1").TextFrame.Characters.Text = ""
End If
End Sub
Actually after considering this further you really are trying to get comment to act as you want. So I recommend Resize all comments in the selected area and on the same link further down the page Show Excel Comments in Centre of Active Window.
These get you closer to what i think you want.
How about a pop-up text box? I.e., the user clicks on the cell and a pop-up form with the text appears. The best part is you can make the pop-up as big as you want.
Personally, I would make the pop-up resizable, but with only the Close button at top. I can't think of a way to trigger this form with just a mouse rollover, but I'm only using 2003. Later versions allow you more tricks.
xlSheet.Range(xlSheet.Cells(rowCount,1), xlSheet.Cells(rowCount,8)).Merge
xlSheet.Range(xlSheet.Cells(rowCount,1), xlSheet.Cells(rowCount,8)).HorizontalAlignment = 1
xlSheet.Range(xlSheet.Cells(rowCount,1), xlSheet.Cells(rowCount,8)).WrapText = True
xlSheet.Range(xlSheet.Cells(rowCount,1), xlSheet.Cells(rowCount,8)).RowHeight=45