textbox displays wrong color - ms-access

I have a bug:
My Microsoft Access report has a textbox that is supposed to have a black forecolor but displays pink instead.
The code setting the forecolor to black is reached and The forecolor is set to black but when the report is finished the textbox displays a pink number.
There are no other references to the textbox in my code.
The default textbox forecolor is #7F7F7F which is grey.
Further the same code correctly sets other textboxes to a black forecolor.
I have cross-checked properties between the text boxes and they all are the same.
What could I be missing?
This is the function call to set the textbox:
SetPointsTextBox frmWeeklyMotivationSystemReport2.Controls!txtSaturday3, status
Sub SetPointsTextBox(textbox As Control, status As clsStatus2)
If status.DisplayTodaysPoints = 0 And status.DayEvent > 0 Then
textbox = DisplayEventasString(status.DayEvent)
textbox.ForeColor = vbBlue
Else
textbox = status.DisplayTodaysPoints
If status.status = 4 Then
If status.DisplayTodaysPoints > 0 Then
textbox.ForeColor = vbRed
Else
If status.DisplayTodaysPoints = 0 Then
textbox = ""
Else
textbox = 0
textbox.ForeColor = RGB(205, 155, 29)
End If
End If
Else
If status.DisplayTodaysPoints < 0 Then
textbox.ForeColor = vbRed
ElseIf status.status = 2 Or status.status = 9 Then
textbox.ForeColor = vbBlue
Else
textbox.ForeColor = vbBlack 'code gets to here and changes the forecolor to 0
End If
End If
End If
End Sub

deleting and recreating the control worked. thanks for the helpful suggestion.

Related

How can I reset the checkbox to the default value?

I have the following code, and if none of the If or ElseIf statements are satisfied, I'd like the checkbox to return to its original state. When you first view the checkboxes in an untouched state, they are filled in with a black box. Once touched/updated, they go to either a checked or empty state. Hoping this makes sense. Thanks!
Private Sub cgvhd_lim_AfterUpdate()
If cgvhd_lim Then
cgvhd_limext = "Limited"
ElseIf cgvhd_ext1 Then
cgvhd_limext = "Extensive"
ElseIf cgvhd_ext2 Then
cgvhd_limext = "Extensive"
ElseIf cgvhd_ext3 Then
cgvhd_limext = "Extensive"
ElseIf cgvhd_ext4 Then
cgvhd_limext = "Extensive"
ElseIf cgvhd_ext5 Then
cgvhd_limext = "Extensive"
Else
cgvhd_limext = 0
End If
End Sub
To return a checkbox to its default state:
cgvhd_lim = Null

IE automation: scrape <td> in <iframe> through VBA

I am trying to automate IE through VBA to click a button that is embedded in an "iframe" as on screenshot below (image in the last line):
However my code is unsuccesful in referencing the button (the last line doesn't print any value):
Sub intercept()
Dim my_title As String
my_title = "Accounting"
marker = 0
Set objShell = CreateObject("Shell.Application")
IE_count = objShell.Windows.Count
For x = 0 To (IE_count - 1)
On Error Resume Next ' sometimes more web pages are counted than are open
page_url = objShell.Windows(x).Document.Location
page_title = objShell.Windows(x).Document.Title
If page_title Like my_title & "*" Then 'compare to find if the desired web page is already open
Set IE = objShell.Windows(x)
marker = 1
Exit For
Else
End If
Next
If marker = 0 Then
MsgBox ("A matching webpage was NOT found")
Else
MsgBox ("A matching webpage was found")
End If
Set mytable = IE.Document.frames(1).Document.tables(1)
Debug.Print mytable.getElementsByTagName("td").Length
End Sub
I have also tried: IE.Document.frames(0).Document.tables(0).
Any help on how to click on this element is appreciated.

Access - If form maximized then allow scrollbars

I have found this API that checks whether form is maximized :
ACC2000: How to Determine If a Form Is Maximized or Minimized
Now I want to use this API to allow Scrollbars on form, If It's maximized. Problem is that when It get's maximized, scrollbars are not visible until I click on some control in detail section. Same way when form is restored - scrollbars don't dissapear until I click on some control. Any way to fix this ?
I tried this (I have to click Field1 after this code, focus not working):
Private Sub Form_Current()
If Maximized = True Then
Me.ScrollBars = 2
Else
Me.ScrollBars = 0
End If
Me.Field1.SetFocus
End Sub
and this (when seting Me.TimerInterval=0 nothing happens, otherwise It's working but keeps triggering timer event):
Private Sub Form_Timer()
If Maximized = True Then
Me.ScrollBars = 2
Else
Me.ScrollBars = 0
End If
Me.Field1.SetFocus
Me.TimerInterval = 0
End Sub
I managed, in resize event code works just fine:
If Maximized = True Then
Me.ScrollBars = 2
Else
Me.ScrollBars = 0
End If
Me.Field1.SetFocus

Access VBA If statement to Change Back and Font color of a report field

I'm trying to make a field on a report highlight in red with white bold font on a report when it has an "S" populated. This keeps making all records in the field red. Please help!
Private Sub Report_Activate()
If Me![PULL STATUS] = "S" Then
Me![PULL STATUS].BackColor = vbRed
Me![PULL STATUS].FontBold = True
Me![PULL STATUS].ForeColor = vbWhite
End If
End Sub
The code you have should be contained in the On Format event of the Detail section of the report. When you set the BackColor, FontBold, and ForeColorit stays that way until it is changed again.
So what you need is an else statement to perform the opposite if not true. Something like:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Me![PULL STATUS] = "S" Then
Me![PULL STATUS].BackColor = vbRed
Me![PULL STATUS].FontBold = True
Me![PULL STATUS].ForeColor = vbWhite
Else
Me![PULL STATUS].BackColor = vbWhite
Me![PULL STATUS].FontBold = False
Me![PULL STATUS].ForeColor = vbBlack
End If
End Sub
MS Access uses Conditional Formatting - much like MS Excel; I recommend this instead of using VBA to change the backcolor pragmatically. This should work well for 'Continuous Forms.'

Confirmation prompt for change to value on an Access form

I am trying to revert back to the original value if, at the MsgBox prompt, the user chooses "No". However, this is not happening. Can you please have a look to see where I am going wrong?
Private Sub txtNov2_AfterUpdate()
Dim x As Integer
Dim NewValue As Integer
Dim OrigValue As Integer
NewValue = Me.txtNov2.Value
OrigValue = [Forms]![DataEntry]![txtNov2].OldValue 'Me.txtNov2.OldValue
If NewValue <> OrigValue Then
x = MsgBox("Value Has Changed Do you Want to Update?", vbQuestion + vbYesNo, "Value Change")
If x = vbYes Then
MsgBox ("Please Press Update Button")
btnUpdateData2.SetFocus
Else
txtNov2.SetFocus
'Me.Undo
txtNov2.Value = OrigValue
'Cancel = True
End If
End If
End Sub
It appears to me that your code is working, as far as it goes. I open the form...
...and change the value from 123 to 124...
...then when I hit the [Tab] key so the control loses the focus I get the MsgBox...
...and if I choose "No" then the value reverts to 123
The only difference between that state and the initial state (when I first opened the form) is that the form is still "dirty", as indicated by the "pencil" icon in the record selector on the left side of the form. If you want to completely undo all changes to the form then try replacing...
Else
txtNov2.SetFocus
'Me.Undo
txtNov2.Value = OrigValue
'Cancel = True
End If
...with...
Else
DoCmd.RunCommand acCmdUndo
End If