How to fit VERY long condition in conditional formatting - vba

I have a very long condition, about 3,000 characters. Access has only space for about one tenth of that.
Is there some other way to set conditional formatting on a textbox besides through the dialogue, or can I do it in VBA and, if so, HOW?
I have conditional formatting on a bunch of textboxes that trigger when the report is opened.

Would be curious to know if the VBA approach worked?
Another idea: create a hidden field on the form and set it's value based on your 3000-character condition. If you are just trying to have 1 conditional expression, you could give this hidden field a false/true or 0/1 value; if you want mulitple conditions, you could give it a value of 0, 1, 2, or 3 corresponding to the conditions you want applied. In either case, your conditional expression test(s) is(are) now trivial: [HiddenFieldName]=ConditionValue

According to Access' Help topic, the FormatConditions Collection has methods (Add, Delete, Modify) which should allow you to adjust your FormatConditions with VBA code. I've never tried, so offer no opinion as to whether this would be a practical approach for you.
I also tried to find out if there is a capacity limit for the number of characters FormatConditions can accept. I didn't find anything there.

Yes, you can manipulate Format Conditions in VBA. There's a full detailed article knowledgebase article at http://support.microsoft.com/kb/304104.
Code snippet here showing a basic example. Refer to the above link to get the VBA for AddFormats:
Public Function HighLightForeignKeys(argFieldName As String, argFieldValue As Integer)
Dim FormatCondition As String
Dim CodeReception As Integer
FormatCondition = "[" & argFieldName & "] = " & ArgFieldValue
With Me.ID
.FormatConditions.Delete
.FormatConditions.Add acExpression, , FormatCondition
.FormatConditions(0).BackColor = 16510422
AddFormats Me.ID, Me
End With
End Function

I dont know if this is what you were after, since you mentioned there was only a tiny box to enter all of your conditional text. Others have shown you VBA solutions - since you asked if that was one way to achieve it.
I have always resorted to using the "zoom" feature which is accessible via the SHIFT-F2 keystroke. Is that what you were after? I think it goes back several Access versions too.
A good set of Access shortcut keystrokes is here:
http://www.joyedaniels.com/keys_access.htm

Related

cannot get value from a cell in libreoffice 6.4.3.2 basic

I am new to libreoffice basic, i have experience with VBA but this libreoffice is different.
I just want to get cell value but it always return zero value to me while the actuall cell can be text or number.
Here is a partial of my simple code.
Sub test_moved()
Dim Doc As Object
'worksheet
Dim sh_village As Object
Dim sh_cbc As Object
sh_village = ThisComponent.CurrentController.getActiveSheet()
'sh_village = Doc.Sheets.getByName("VillageFinal")
'sh_village = Doc.Sheets(1)
Msgbox(sh_village.getCellrangeByName("B2").getValue())
Msgbox(sh_village.getCellrangeByName("B2").Value)
Msgbox(sh_village.getCellByPosition(1,1).Value)
msgbox("The process is completed.")
End Sub
Do we need to do prior task before start coding?
The code works correctly for numeric values. However, for strings, including strings that look like a number, it will display 0 because there is no numeric value.
What you probably want instead is:
MsgBox(sh_village.getCellRangeByName("B2").getString())
Also check out Format -> Cells -> Number to see how the data is displayed in the cell. And be on the lookout for a single quote at the front of the value in the formula bar (for example '42), because that means it is a string. Delete the quote to make it a number.
i have experience with VBA but this libreoffice is different.
Yes, LibreOffice Basic is a different language from VBA and the LibreOffice API is very different from the MS Office API. Knowing that will help you use it more effectively. If possible, avoid Option Compatible, because it won't fix most problems and will only muddy the waters.

vba inputBox: Alternative Solutions on “cancel” and “OK” with an empty textbox

For some reason, the solution those two questions (Q1, Q2) give on how to differentiate between "cancel" and "ok with an empty string" for an inputbox don't always work within a specific code of mine. I wasn't able to reproduce the problem so far so I'm looking for a different solution.
In my scenario, the inputbox pops up with a default value it got from somewhere else. So far I only needed to change this value through the inputbox so the simple check for if len(inputboxString) = 0 then to determine if cancel was pressed was working well. Now I got the case where I need to "clear" the existing default value. I'm trying to avoid using StrPtr for the reason I described above.
Here's the code that worked so far (as long as I don't need to use the inputbox to delete the value, since 'strInputBox = ""' is reserved for the cancel-event and I want to avoid using 'strPtr').
Dim strSomeStringFromSomewhere as String
strSomeStringFromSomewhere = someSubThatGetsTheStringValueFromSomeWhere
Dim strInputBox As String
strInputBox = InputBox(Prompt:="Edit/Delete Value", Title:="Title", Default:=strSomeStringFromSomewhere)
If strInputBox = "" then
'do nothing cause cancel was pressed
else
someSubThatWritesTheChangedStringBackToItsOrigin strInputBox
End If
The used value is usually some alphanumeric string e.g. d939d8ej3.
Any hints/ideas for a different user friendly approach would be welcome. (user meaning the person using the inputbox not the person who implements/maintains the code).
I figured out a nice work around, which should work in many other cases as well. In my case a single or multiple spaces are not a valid entries. And since I have to get rid of pre- and succeeding spaces anyway I just use trim(strInputBox) which will "clear" my value.
So the user just has to enter a space into the inputbox, which is good enough for prototypes.

Multiple Criteria using autofilter on the same range, autofilter only takes last Criteria Used

I'm trying to filter multiple filters based on user input from a listbox on the same range.
However, for some reason the autosort method only sort the target range using the last criteria from testing.
I have searched everywhere, tested out array solutions (reading list info into an array), writing a range of values for filters on worksheets, changing variable type/operator to no avail. Nothing works.
Thanks for your time for reading this, would appreciate it if someone could help me with this.
dim lifecycle as range
dim List2String as string
Set lifeCycle = defineColRange(startWs, "Lifecycle Comments (Saks)", True, False)
For i = 0 To ListBox2_Lifecomments.ListCount - 1
'looping though the listbox2 to retrieve values
List2String = ListBox2_Lifecomments.List(i)
startWs.UsedRange.AutoFilter Field:=lifeCycle.Column, Criteria1:="<>" & List2String
Next i
startWs.UsedRange.SpecialCells(xlCellTypeVisible).Interior.Color = rgbLightPink 'testing to see if filter works
After some more digging, and rethinking, essentially I was asking the wrong questions.
The problem statement should be: "How to filter a range NOT equal to multiple criterias?"
It is documented here: Explaination of why .autosort doesn't work with not equal to with multiple criterias.
Few Solutions were discussed:
Use another a column to help you determine the result you want to achieve. In my example, it would be looping through all values from
user input, and output true/false on another column based on
comparison, then filter that helper column to work around this
problem.
Filter with an impossible values, this is situational. For example, if you want to filter numbers, set up an outofbound criteria for
non-numbers like given in the explanation link above.
Write code to hide the already filtered criteria, and keep filtering what is left with rest of criteria, 2 at a time.
Use advanced filters
Hope this helps others who might get into same problems in the future.

How do I use a shape's ID from another field to define beginX

Background: Novice user and VBA programmer - be gentle, please.
Scenario:
Using a Visio (2010) straight line connector;
Currently 1-D Endpoints.BeginX is as follows:
=PAR(PNT(Milestone.40!Connections.X1,Milestone.40!Connections.Y1))
What I have:
A data field in the same shape called BeginItem that contains the Visio ID (e.g. 87) of Milestone.40! above.
What I need to know:
If possible, how to change the formula in 1-D Endpoints.BeginX to something like:
=PAR(PNT(BeginItemValue!Connections.X1,BeginItemValue!Connections.Y1))
and if not possible, is there an alternative way of doing this?
Thanks!
Thanks for helping all. A combination of all advice led me to an alternative solution.
Instead of trying to refer to the field in the Shapesheet that does contain the BeginItemValue, I built the entire string (in VBA) by concatenating the parts and then updated the BeginX value with it.
shpObj.Cells("BeginX").Formula = "=PAR(PNT(" & BeginItemValue & "!Connections.X1," & BeginItemValue & "!Connections.Y1))"
That worked well, although I'm sure there are easier ways of doing it.

Check whether Conditional Formatting is applied or not

Using Excel VBA code, is there any way by which I can check whether a
particular cell has satisfied Conditional Formatting or not?
I have data in a single column with than 80000 cells.
I used the following code but it gives same value for Interior.ColorIndex or Interior.PatternIndex or Font.Bold irrespective of whether the Conditional Formatting is applied or not
Sub Check_CF()
MsgBox Range("B4").Interior.PatternColorIndex
End Sub
My conditional formatting rule is not important. I can change the rule if I am able to check whether it is applied or not.
Found this rather long article with example functions on the subject that might be of help to you:
http://www.xldynamic.com/source/xld.CFConditions.html