D.Spivak
D.Spivak

Reputation: 1

Access-VBA Changing Font and Size of text in form

I am trying to change the font and font size of the text in one box of my form

With Me.[Notes:]
.SetFocus
.FontName = "Verdana"
.FontSize = 8
.ForeColor = vbBlack
End With

I have already looked here

Access VBA programmatically setting font/size not working

And seem to have that working, though I still have a couple of issues.

  1. It changes the text in the right box but on EVERY one of my records, rather than just the one I'm editing.
  2. It only works on text which has been types into the text box directly. Not on text that has been pasted into the form. (This is the reason for the button in the first place)

In case it matters, I'm using MS Access 2016

Thanks in advance,

Daniel

Upvotes: -1

Views: 8944

Answers (1)

jwill
jwill

Reputation: 94

If it's not a continuous form, sounds like you need to add an IF statement to specify under which conditions this should take place. Then place it on the current event of the form.

Private Sub Form_Current()    
if condition met then 
    With Me.[Notes:]
    .SetFocus
    .FontName = "Verdana"
    .FontSize = 8
    .ForeColor = vbBlack
    End With
    end if 
end sub

For the second issue you can set the code (or create a procedure and call it) on the afterupdate event of the field

Private Sub notes_AfterUpdate()
if condition met then 
    With Me.[Notes:]
    .SetFocus
    .FontName = "Verdana"
    .FontSize = 8
    .ForeColor = vbBlack
    End With
    end if 
End Sub

Upvotes: 0

Related Questions