[AccessD] A2000: Inserting HTML codes into a Text Box

Liz Doering ldoering at symphonyinfo.com
Thu Apr 14 13:23:52 CDT 2005


Steve,

I just create buttons along side of my text box for this, with names like
"Paragraph" or "Bold".  Use the & to give the alt+p or alt+b keyboard
functionality.  This way, the user can just add the symbol they want as they
are typing.

Then on the button click do this:

Me.txtMyHTMLTextBox = Me.txtMyHTMLTextBox & " add this"
Me.txtMyHTMLTextBox.SetFocus
Me.txtMyHTMLTextBox.SelStart = Len(Me.txtMyHTMLTextBox) + 1

You have to set the focus back on the end of your text, otherwise it will
stay on the button.

You could also set a hidden field for off and on, so that the first time she
hit the button it would produce <b> and the second time it would produce
</b>.


Liz


-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Steve Erbach
Sent: Thursday, April 14, 2005 11:13 AM
To: Access Developers discussion and problem solving
Subject: [AccessD] A2000: Inserting HTML codes into a Text Box

Dear Group,

This is far from urgent. I'm simply trying to make it easier for a client.

I've set up a form for my client to add news items to a web page I put
together for her. There are text boxes for a date, a title for the
item, and for the text of the news item itself. That text box is
called txtNewsItem.

There, of course, is no formatting in a text box; but I'd like to give
my client the option to insert the proper HTML codes for bold, italic,
underline, line break, etc. I could give her a cheat sheat with a few
of the codes listed and how to type them in properly, but I'd like to
go a little further. Is there a way for, say, the <b></b> codes to be
inserted in a text box with a keystroke like Ctrl-B?

I've been experimenting with SendKeys and OnKeyUp. I discovered that
the SendKeys action itself triggers the OnKeyUp event; so a bit of
code like this in the On Key Up event procedure does NOT work
properly:

Private Sub NewsItem_KeyUp(KeyCode As Integer, Shift As Integer)
If Shift And acCtrlMask Then
   Select Case KeyCode
      Case Asc("B"), Asc("b")
         SendKeys "<b></b>"
         ... etc.

So I moved the SendKeys to a Click event procedure of a button off to
the side of the txtNewsItem text box...but when I use code like this:

Private Sub cmdBold_Click()
   Screen.PreviousControl.SetFocus
   SendKeys "<b></b>"

... the HTML codes are placed at the END of the text in the box. The
cursor position is lost when the button is clicked.

Ideally I'd like the user to be able to select a block of text and
press Ctrl-B and have the HTML <b> and </b> codes appear surrounding
the selected text. Is this even possible?

Regards,

Steve Erbach
Scientific Marketing
Neenah, WI
www.swerbach.com
Security Page: www.swerbach.com/security
-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com






More information about the AccessD mailing list