Setting up some properties for a combobox (scroll, edit, jump) - forms

There are 3 properties that I want to set for some VBA form comboboxes and I don't know if it's possible.
I don't want to let the combobox editable. Right now if the user types something in it that it submits the form it will send that value... I want to let him choose only from the values I added in the Combobox.
I want to make the list of items in the combobox scroll-able. Right now I'm able to scroll through the list if I use the scroll-bar but I don't know why I can't scroll with the mouse scroll.
And I want to jump to some item if I start typing. Let's say I have the months of the year in one combobox... if I start to type mar I want it to jump to march. I know that for the html forms this properties is by default but I don't know about VBA forms...
Thanks a lot

Of the behaviours you want, some are possible with settings on the Combo, others you will need to code
List of Months: Put a list of entries on a (hidden) sheet and name the range. Set .RowSource to that range
Match as you type: Set properties .MatchEntry = fmMatchEntryComplete and .MatchRequired = True
Reject non list entries: A Combo with these settings will allow you to type an invalid entry, but will reject it with an error message popup when you commit. If you want to silently reject invalid data as you type, you will need to code it.
If you want the selected value returned to a sheet, set .ControlSource to a cell address (preferable a named range)
By "...scroll with the mouse scroll..." I assume you mean the mouse wheel. Unfortunatley Forms don't support mouse wheel scroll. You will have to code it yourself. There is a Microsoft patch for this at here (not tried it myself yet)
Sample code to silently reject invalid entries
Private Sub cmbMonth_Change()
Static idx As Long
Dim Match As Boolean
Dim i As Long
If cmbMonth.Value = "" Then Exit Sub
If idx = 0 Then idx = 1
i = idx
Match = False
For i = 0 To cmbMonth.ListCount
If cmbMonth.List((i + idx - 1) Mod cmbMonth.ListCount) Like cmbMonth.Value & "*" Then
cmbMonth.ListIndex = (i + idx - 1) Mod cmbMonth.ListCount
Match = True
Exit For
End If
Next
If Not Match Then
cmbMonth.Value = Left(cmbMonth.Value, Len(cmbMonth.Value) - 1)
End If
End Sub

Set the propertie MatchEntry of combobox to 1 (fmMatchEntryComplete) and MatchRequired to true for example
combobox1.MatchEntry=1
combobox1.MatchRequired=True
[]'s

Related

Suppress a Text Object Based on Field Value in Object

I have a Text Object that contains a text string followed by a database field Max Weight {table.field}
I want to suppress all of the Text Object whenever {table.field} = 0.
I tried the following formula under Format Text > Common > Suppress
if {table.field} = 0 then true else false
What I get is the field value within the text object either on or off while the text is always suppressed. What do I need to do to make this work? Thanks.
You can try 2 different solutions:
1) Keeping your Max Weight label, create a new Formula in the 'Formula Fields' then enter this code:
if {table.field} = 0 then '' else ToText({table.field})
2) Supressing all text, you have to create a new Formula too, but type this:
if {table.field} = 0 then '' else 'Max Weight ' + ToText({table.field})
This second way, you will create a label that will only appears when your conditions happens, and you must replace the old TextObject with this new Formula. This will cause a blank area, because no text and no weight will show, but it looks like exactly what you need.
I just tested here and it's working. Note that both 'spaces' are in the document. Attached is an image that may help you find the formulas section. Hope you can use it.

Userform for Word with bookmarks and automated Crossreferences

so this is my first programming experience and I am pretty excited about it. However, I have been dealing with a problem:
Goal
My goal is to create a word document with an integrated Userform asking for Name, Title and Startdate at the beginning. The information shall then be reflected in the defined areas in the document.
Dim Name As Range
Set Name = ActiveDocument.Bookmarks("Name").Range
Name.Text = Me.TextBox1.Value
Dim Title As Range
Set Title = ActiveDocument.Bookmarks("Title").Range
Title.Text = Me.TextBox2.Value
Dim Startdate As Range
Set Startdate = ActiveDocument.Bookmarks("Startdate").Range
Startdate.Text = Me.TextBox3.Value
Me.Repaint
UserForm1.Hide
I could successfully integrate the Userform, assigning the information to the bookmarks. Since I can only use 1 bookmark I tried my luck with text properties but it does not work.
The next thing I tried was to apply 1 bookmark and several cross-references throughout the text, meaning that I have to add a command to the code that updates all cross-references automatically I tried it with sub updateAllFields()
Dim Name As Range
Set Name = ActiveDocument.Bookmarks("Name").Range
Name.Text = Me.TextBox1.Value
Dim Title As Range
Set Title = ActiveDocument.Bookmarks("Title").Range
Title.Text = Me.TextBox2.Value
Dim Startdate As Range
Set Startdate = ActiveDocument.Bookmarks("Startdate").Range
Startdate.Text = Me.TextBox3.Value
Me.Repaint
Sub UpdateAllFields()
UserForm1.Hide
But this one gives me an error message. Can somebody help, please?
Stick to the fields path as it may be less work to maintain.
I: Create three custom document properties for each field (Name, Title, StartDate)
Steps:
1) Click File | Properties | Advanced properties | Custom
2) Enter the following data:
- Name: customName
- Text: Enter name
3) Click the button "Add"
4) Repeat steps 2 and 3 for fields Title and StartDate (remember to add the "custom" word before so you can identify them later easily
This is how it should look like:
II: Add the fields of each custom property created to the word document
Steps:
1) Position the cursor where you want the field in the word document
2) Click Insert | Quick parts | Field | Categories: Document information | DocProperty | < name of the doc property >
3) Click Ok
4) Repeat the process for each field
Note: You can add the same field / custom property, in different parts of the document
III: Create the UserForm and add the controls
Steps:
1) Add the UserForm
2) Add three textboxes and set the name property to:
- txtName
- txtTitle
- txtStartDate
for each one.
3) Add a command button and set its name to cmdInsertData
This is how it should look like:
To set the name of each control look for (Name) at the properties window:
IV: Add code to show the userform at startup
Steps:
1) Launch the VBE by pressing Alt + F11 (or activating the developer tab in the ribbon and pressing the Visual basic button
2) Add the following code to the "ThisDocument" object:
Private Sub Document_Open()
UserForm1.Show
End Sub
V: Add the form code
Steps:
1) Right click the UserForm1 object and select "View Code"
2) Add the following code:
Private Sub cmdInsertData_Click()
' Update the properties values
ThisDocument.CustomDocumentProperties("customName").Value = Me.txtName.Value
ThisDocument.CustomDocumentProperties("customTitle").Value = Me.txtTitle.Value
ThisDocument.CustomDocumentProperties("customStartDate").Value = Me.txtStartDate.Value
' Show changes of document properties in document
ThisDocument.Fields.Update
' Hide the userform
UserForm1.Hide
End Sub
Remember to save your document as macro-enabled
Close it and reopen it
Give it a try and let me know
Disclaimer: As this article states, there is a right way to handle showing a userform properly, but I'll leave it the "easy" way for simplicity purposes.

Access VBA to Change an Image in a Continuous Form

I am trying to create a receipt form where people will confirm if they've received the full quantity of an order. As part of this, I want the following to happen:
If they received the full quantity, a green check mark appears
If they received a partial quantity, an orange triangle appears
If they received no items, a red x appears
To accomplish this, I'm using a continuous form with 3 image files for each situation. I'm using the code below to change the image when the quantity is changed. The problem is, when the quantity is change on 1 line, the symbol changes for all lines. I'll post pictures as well.
Any thoughts on how I can fix this?
I'm open to other methods of accomplishing this idea too.
Private Sub FinalQTY_AfterUpdate()
If IsNull(Me.FinalQty) Then
MsgBox "You must enter a quantity for this item"
Me.FinalQty.SetFocus
Exit Sub
Else
LValue = Me.[FinalQty]
If IsNumeric(LValue) = 0 Then
Me.FinalQty = ""
MsgBox "Qty must be a numeric value"
Me.QTY.SetFocus
Exit Sub
End If
End If
Me.FinalTotalPrice = Me.FinalPrice * Me.FinalQty
If Me.FinalQty = 0 Then
Me.Yes.Visible = False
Me.Change.Visible = False
Me.No.Visible = True
End If
If Me.FinalQty < Me.QTY Then
Me.Yes.Visible = False
Me.Change.Visible = True
Me.No.Visible = False
End If
If Me.FinalQty = Me.QTY Then
Me.Yes.Visible = True
Me.Change.Visible = False
Me.No.Visible = False
End If
End Sub
This is before I adjust the quantity:
This is after I adjust the qty of only the second line:
Since the formatting of each record displayed by a continuous form is inherited from the form design template, any changes to the template will be automatically applied to all records displayed by the form, aside from Conditional Formatting rules in effect or the handful of properties which may changed via the OnPaint event of the Detail section.
One possible alternative might be to add a new field to your table with a data type of OLE Object and populate the value on the AfterUpdate event using the AppendChunk method, sourcing image data from a separate table containing three records corresponding to your green tick, orange triangle, and red cross images.

How to change background color for each two rows in SSRS in a group

How can I write the expression in order to change background color for each two rows in SSRS?
I need something like that:
I tried expression
=IIF(Fields!Type.Value="2016 Submitted" , "LightBlue",
IIF(Fields!Type.Value="2015 Submitted" , "LightBlue",
Nothing))
But because some months dont have values it looks like this:
If I try this expression I get below:
=IIF(RunningValue(Fields!Count.Value, CountDistinct, Nothing) MOD 2 = 1, "White", "PaleTurquoise")
Dance-Henry I tried your code
=IIF(RowNumber(Nothing) Mod 4 = 1 or RowNumber(Nothing) Mod 4 = 2, "Aqua","White")
and this is what i got:
You can select the row in design pane and press F4 to setup property BackgroundColor as =IIF(RowNumber(Nothing) Mod 4 = 1 or RowNumber(Nothing) Mod 4 = 2, "Aqua","White")
Captures are attached. Do it accordingly.
RESULT is something like this
After going thru the link https://blogs.msdn.microsoft.com/chrishays/2004/08/30/green-bar-matrix/
Tested and it works well for the Green Bar Effect for Matrix. I will show it step by step here as for later reference.
Step 1: Create the Matrix and add one more column under the innermost row grouping in your matrix. (ColorNameTextbox here)
Step 2: Select the textbox of ColorNameTextbox and press F4 to setup BackgroundColor property as =Value shown below.
Step 3: Select the textbox of Matrix cell and press F4 to setup BackgroundColor property as =ReportItems!ColorNameTextbox.Value shown below.
Step 4: Drag the inner grouping header (ColorNameTextbox) to be as narrow as possible.
Step 5: Preview Pane to check the result.
If you could add a hidden color_group column and populate it with a new number at each point you want to change the color (in your case 1,1,2,2,3,3,4,4) then you could use something like the following (which works for varying size groups):
IIF(RunningValue(Fields!color_group.Value, CountDistinct, Nothing) MOD 2 = 1, "White", "PaleTurquoise")
I had a similar problem where I could not come up with alternating rows because my data has Column Groups that were the RowNumber(Nothing) method to fail. Learning from all the other posts here this is how I resolved it in steps.
I added the following code into the report properties, that provides a function to get the row number, each time it is called. The function increments the row count each time it is called. >>Right click space around the report >> Properties >> Code. Alternatively go to Code Properties Window, when the report is selected.
Add the following lines:
Public Row_Sum As Decimal = 0
Public Function Lookup_Sum( ) As integer
Row_Sum = Row_Sum + 1
Return Row_Sum
End Function
I added a new column at the beginning of the rows called No. that would calculate and show the row number.Right click the first column >>Insert Column>>Inside Group-Left.
On the expression for the new report add this line of code. Also take a note of the name of the TextBox that will have the No. Value. It will be needed in the next step. In my case the TextBox is called TextBox6 (Properties Window). >>Right Click Cell>>Expression.
Add the code:
=Code.Lookup_Sum()
I highlighted the entire row and went to the Background property and added the following expression to compute the row number.
Add the code(TextBox6 is the name Textbox name noted above):
=IIF(VAL(ReportItems!Textbox6.Value) MOD 2, "LIGHTBLUE", "WHITE")

MS Access - Close form without save design changes, acSaveNo doesnt work

I have a Front End/Back End app in MS Access and I'm having some problems with performance when I close forms.
These forms are always saving before close because in Form_Open I hide some columns and edit the caption. Then, when I close the form, it saves the hidden columns and wastes much time!
I have already done a lot of settings modifications in Access for optimize for FE/BE. But I'm still have problems with forms that save before close. On save event it really wastes a lot of time. With the hide/edit columns routine it takes 20s to save. Without the routine it takes 1s or less, but my data is not saved.
How could I hide/edit these columns without the need to save the form afterwards? Or how could I close the form without saving structure changes?
Unfortunately Access doesn't have a BeforeClose event, and in a Close or Unload event it saves before going to this sub, so I can't cancel it to close later in code.
Hide Code:
'show all columns
For i = 1 To 8
Form_Y_SubF_LP.Controls("Item_00" & i).ColumnHidden = False
Form_Y_SubF_LP.Controls("Quantity_00" & i).ColumnHidden = False
Form_Y_SubF_LP.Controls("DistributionEQ_00" & i).ColumnHidden = False
Next
'Hide unnecessary columns
For i = 8 To ProtQuant + 1 Step -1
Form_Y_SubF_LP.Controls("Item_00" & i).ColumnHidden = True
Form_Y_SubF_LP.Controls("Quantity_00" & i).ColumnHidden = True
Form_Y_SubF_LP.Controls("DistributionEQ_00" & i).ColumnHidden = True
Next
'Change the caption of columns to the real name of each prototype
prot = DLookup("[Prototype]", "Y_Configurações", "[Program]= '" & ProgramName & "'")
For i = 0 To UBound(Split(prot, ";"), 1)
Form_Y_SubF_LP.Controls("Item_00" & i).Properties("Caption") = "Item_" & Split(prot, ";")(i)
Form_Y_SubF_LP.Controls("Quantity_00" & i).Properties("Caption") = "Quantity_" & Split(prot, ";")(i)
Form_Y_SubF_LP.Controls("DistributionEQ_00" & i).Properties("Caption") = "DistributionEQ_" & Split(prot, ";")(i)
Next
A simple solution is to set Close Button = No on the form's property sheet, then add a command button, cmdCloseMe, with this for its On Click event:
Private Sub cmdCloseMe_Click()
DoCmd.Close acForm, Me.Name, acSaveNo
End Sub
If you need your form displayed in Datasheet View, you would need to embed it in a subform control of another form and add the cmdCloseMe button to that form.