chtobj.Chart.ChartArea.Format.Fill.Visible= msoFalse getting mismatch error - ms-access

I have created a object and need to set Format.Glow, Format.Fill and Format.SoftEdge.Radius etc
The code from excel uses With Selection but that's not allowed in access. I used the watch window and see the properties but can't assign anything.
enter code here
For Each chtobj In shtTemp.ChartObjects
If chtobj.Name = "Chart4" Then
Debug.Print chtobj.Name
'
chtobj.Chart.ChartArea.Format.Fill.Visible = msoTrue
chtobj.Chart.ChartArea.Format.ForeColor.RGB = RGB(0, 176, 80)
chtobj.Chart.ChartArea.Format.Transparency = 0
chtobj.Chart.ChartArea.Format.Solid
With chtobj.Chart.ChartArea.Format.Glow
.Color.RGB = RGB(255, 255, 0)
.Transparency = 0
.Radius = 10
End With
chtobj.Chart.ChartArea.Format.Line.Visible = msoFalse
chtobj.Chart.ChartArea.Format.SoftEdge.Radius = 1
End If
Next

I found the correct syntax for VBA:
chtobj.Chart.Shapes.Parent.ChartArea.Format.Fill.Visible = msoTrue

Related

How can I check a checkbox in Access as I move from record to record?

I have an Access database which has a checkbox that I need to see if it's "false" or "true" as I go from record to record. If the checkbox is true the label font color and name should change.
This is my code but it's not working properly:
Private Sub Check796_Click()
lngRed = RGB(255, 0, 0)
lngBlack = RGB(0, 0, 0)
If Me.Check796 = vbTrue Then
Me.Label797.Caption = "Hold"
Me.Label797.ForeColor = lngRed
Else
Me.Label797.Caption = "UnHold"
Me.Label797.ForeColor = lngBlack
End If
End Sub
If it's checked it should be red and say "Hold" but, if it's unchecked it should say "UnHold". If I check the "Hold" checkbox it's works but, when I go to the next record which is unchecked it says "Hold" as well. When I close the application and go back into the record with the checkbox clicked the label says "UnHold" when it should say "Hold".
Just execute the code again on Form_Current:
Private Sub Form_Current()
lngRed = RGB(255, 0, 0)
lngBlack = RGB(0, 0, 0)
If Me.Check796 = vbTrue Then
Me.Label797.Caption = "Hold"
Me.Label797.ForeColor = lngRed
Else
Me.Label797.Caption = "UnHold"
Me.Label797.ForeColor = lngBlack
End If
End Sub
To do it without any VBA:
Add your checkbox with the Control Source set to your boolean
(Yes/No) field.
Add a textbox (format to look like a label).
Give it a Control
Source of =Choose(Abs([Check796])+1,'UnHold','Hold')
A boolean
returns -1 for TRUE and 0 for FALSE.
ABS removes the sign, so
it's now 0 and 1.
Add 1 as CHOOSE needs to start at 1.
Select the text and in the FORMAT ribbon in Form Design Tools
select Conditional Formatting.
Select Field Value Is equal to
"Hold" and format as red font.

Remove NaN in Nested iif in SSRS expression

New to SQL-SSRS
How do I add functionality to the below code to change returned NaN values to 0 or blank? What I think is happening is in situations that the sum of Agreed and Disagreed = 0 I am getting this Nan. I think this would be easier for me if I wasnt dealing with the Agreed and Disagreed categories. Again, new to SQL programming. Any help would be greatly appreciated.
=(Sum(iif(Fields!Response.Value = "Agreed",Fields!Days.Value,0)) + Sum(iif(Fields!Response.Value = "Disagreed",Fields!Days.Value,0)))/(Sum(iif(Fields!Response.Value = "Agreed",Fields!Fq.Value,0)) + Sum(iif(Fields!Response.Value = "Disagreed",Fields!Fq.Value,0)))
Try something like below,
=Replace((Sum(IIF(Fields!Response.Value = "Agreed",Fields!Days.Value,0)) +
Sum(IIF(Fields!Response.Value = "Disagreed",Fields!Days.Value,0))),"NaN","0")
/ Replace((Sum(IIF(Fields!Response.Value = "Agreed",Fields!Fq.Value,0))
+ Sum(IIF(Fields!Response.Value = "Disagreed",Fields!Fq.Value,0))),"NaN","0")
Also, look at this
Rather than replacing the text returned from dividing by zero, you should handle the DIV 0 issue in the expression:
=IIF(
SUM(IIF(Fields!Response.Value = "Agreed" OR Fields!Response.Value = "Disagreed", Fields!Fq.Value, 0)) = 0, 0,
SUM(IIF(Fields!Response.Value = "Agreed" OR Fields!Response.Value = "Disagreed", Fields!Days.Value, 0)))
/IIF(
SUM(IIF(Fields!Response.Value = "Agreed" OR Fields!Response.Value = "Disagreed", Fields!Fq.Value, 0)) = 0, 1,
SUM(IIF(Fields!Response.Value = "Agreed" OR Fields!Response.Value = "Disagreed", Fields!Fq.Value, 0)))
If the SUM is zero, the calculation is 0 / 1 otherwise it's the SUM(Days) / SUM(Fq) where the Response is Agreed or Disagreed.
And rather than two sum, just use an OR in the one.
Public Function Divider (ByVal Dividend As Double, ByVal Divisor As Double)
If IsNothing(Divisor) Or Divisor = 0
Return 0
Else
Return Dividend/Divisor
End If
End Function
this function enables you to write a custom code which fixes all problems with Nan .
this can be called by below
=Code.Divider(Fields!FieldA.Value, Fields!FieldB.Value)
your code is as below
=Code.Divider(((Sum(iif(Fields!Response.Value = "Agreed",Fields!Days.Value,0)) + Sum(iif(Fields!Response.Value = "Disagreed",Fields!Days.Value,0))), ((Sum(iif(Fields!Response.Value = "Agreed",Fields!Fq.Value,0)) + Sum(iif(Fields!Response.Value = "Disagreed",Fields!Fq.Value,0)))))

Textbox_AfterUpdate not working with another control

Why I can't change value of another control in access form in afterupdate function?
Private Sub cNPSrate_AfterUpdate() 'Form_new_opinion_in!
If Not IsNull(cNPSRate) Then
Select Case cNPSRate
Case 1 To 6
cNPSRate.BackColor = RGB(255, 0, 0) And cSegmentNPS.Text = "KRYTYK"
Case 7 To 8
cNPSRate.BackColor = RGB(255, 255, 0) And cSegmentNPS.Text = "NEUTRALNY"
Case 9 To 10
cNPSRate.BackColor = RGB(0, 255, 0) And cSegmentNPS.Text = "PROMOTOR"
End Select
Else
cNPSRate.BackColor = RGB(255, 255, 255) And cSegmentNPS.Text = Null
End If
End Sub
The code works if I remove And cSegmentNPS.Text. Can't I use another control in this function or I make some mistake?
cNPSRate and cSegmentNPS are TEXTBOXes
A text box's .Text property is only available when that text box has focus. At any other time, use its .Value property instead.
I would also put each action on its own line instead of combining them with And on one line.
So I suggest you revise your code to follow this pattern ...
cNPSRate.BackColor = RGB(255, 0, 0)
cSegmentNPS.Value = "KRYTYK"

VBA Chart Coloring

I've got a problem with coloring chosen records from chart with VBA.
I've got some code which colors every record in my chart. Here it is:
SeriesCount = MyChart.SeriesCollection.Count
For i = 1 To SeriesCount
MyChart.SeriesCollection(i).Interior.Color = RGB(255, 0, 0)
Next
What I want is to change color of chosen record, for example 20 on picture below. Thanks for help.
You can hard code it by position. Since 20 is the 5th point in the graph you can use this code:
ActiveChart.SeriesCollection(1).Points(5).Interior.color = RGB(55, 130, 150)
If you need to search for 20, it's a little more difficult.
Sub color()
Dim MyChart As Chart
Set MyChart = ActiveChart
SeriesCount = MyChart.SeriesCollection.Count
For i = 1 To SeriesCount
Set s = MyChart.SeriesCollection(i)
vals = s.XValues
For x = LBound(vals) To UBound(vals)
If vals(x) = 20 Then
s.Points(x).Interior.color = RGB(55, 130, 150)
Else
s.Points(x).Interior.color = RGB(255, 0, 0)
End If
Next x
Next
End Sub
Tested:

ms-access/VBA: invalid reference to the scalemode property (error on adding a border to a report)

I'm trying to use the following function to draw a border around my report:
Public Function PageBorder(ByVal strReportName As String)
Dim Rpt As Report, lngColor As Long
Dim sngTop As Single, sngLeft As Single
Dim sngwidth As Single, sngheight As Single
On Error GoTo PageBorder_Err
'DRAW DOUBLE LINED BORDER
Set Rpt = Reports(strReportName)
'Set scale to pixels
Rpt.ScaleMode = 3
'Top inside edge
sngTop = Rpt.ScaleTop
'Left inside edge
sngLeft = Rpt.ScaleLeft
'Width inside edge
sngwidth = Rpt.ScaleWidth
'Height inside edge
sngheight = Rpt.ScaleHeight
'color value
lngColor = RGB(0, 0, 255)
'Draw page Border
Rpt.Line (sngTop, sngLeft)-(sngwidth, sngheight), lngColor, B
sngTop = Rpt.ScaleTop + 10
sngLeft = Rpt.ScaleLeft + 10
sngwidth = Rpt.ScaleWidth - 10
sngheight = Rpt.ScaleHeight - 10
Rpt.Line (sngTop, sngLeft)-(sngwidth, sngheight), lngColor, B
PageBorder_Exit:
Exit Function
PageBorder_Err:
MsgBox Err.Description, , "PageBorder"
Resume PageBorder_Exit
End Function
(source: http://msaccesstips.com/2007/08/reports-page-border/)
I added pageborder "myreport" to my report_open, but it returns the following error:
error 2455: invalid reference to the scalemode property.
anyone have any clue about this ?
Try the On Page event.
Access help: "You can set the ScaleMode property by using a macro or a Visual Basic event procedure specified by a section's OnPrint property setting."