I would firstly, like to add a bullet to a Form textbox as soon as the user begins typing and secondly, add a bullet to each new line. I have code that works fine when the datatype is short text but I am unable to get something that works for long text/ memo. I am using Ms Access 2013. This is what I use for the short text:
[Private Sub Meeting_Notes_Change()
If Len(Trim(Meeting_Notes.Text)) = 1 And _
Meeting_Notes.Text <> "• " Then _
Meeting_Notes.Text = "• " & Meeting_Notes.Text
End Sub]
[Private Sub Meeting_Notes_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
KeyCode = 0
Meeting_Notes.Text = Meeting_Notes.Text & Chr(13) & Chr(10) & "• "
End If
End Sub]
Your code is nearly there. In your subs, you should add code to tell the cursor to go to the end of the text. Add this to the end of both subs: - Meeting_Notes.SelectionStart = Meeting_Notes.Text.Length + 1
and you should change your KeyDown event to a KeyUp event. The enter key itself actually fires on the KeyDown event which causes the line return, so you'll want work to take place after that, which is the KeyUp event. Then your code can stay the same, but remove the Chr(10) portion. I hope this helps, and here is my whole code in VB.NET, for reference, which is pretty close in syntax. - Public Class Form1
-
-
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
-
If TextBox1.Text.Length = 1 And TextBox1.Text <> "•" Then
-
TextBox1.Text = TextBox1.Text.Insert(0, "•")
-
TextBox1.SelectionStart = TextBox1.Text.Length + 1
-
End If
-
End Sub
-
-
Private Sub TextBox1_KeyUp(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyUp
-
Dim KeyCode As Integer = e.KeyCode
-
If KeyCode = 13 Then
-
TextBox1.Text = TextBox1.Text & "•"
-
TextBox1.SelectionStart = TextBox1.Text.Length
-
End If
-
End Sub
-
-
End Class
7 1579
Your code is nearly there. In your subs, you should add code to tell the cursor to go to the end of the text. Add this to the end of both subs: - Meeting_Notes.SelectionStart = Meeting_Notes.Text.Length + 1
and you should change your KeyDown event to a KeyUp event. The enter key itself actually fires on the KeyDown event which causes the line return, so you'll want work to take place after that, which is the KeyUp event. Then your code can stay the same, but remove the Chr(10) portion. I hope this helps, and here is my whole code in VB.NET, for reference, which is pretty close in syntax. - Public Class Form1
-
-
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
-
If TextBox1.Text.Length = 1 And TextBox1.Text <> "•" Then
-
TextBox1.Text = TextBox1.Text.Insert(0, "•")
-
TextBox1.SelectionStart = TextBox1.Text.Length + 1
-
End If
-
End Sub
-
-
Private Sub TextBox1_KeyUp(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyUp
-
Dim KeyCode As Integer = e.KeyCode
-
If KeyCode = 13 Then
-
TextBox1.Text = TextBox1.Text & "•"
-
TextBox1.SelectionStart = TextBox1.Text.Length
-
End If
-
End Sub
-
-
End Class
I think this works, but in order to insert your bullet, I have used a Shift Return Key. The unshifted Return Key operates in the usual way.
The Shift Return Key can be used in the middle of the text, as well as the end.
It also strips any unused bullets at the end of the text. - Option Compare Database
-
Option Explicit
-
-
Private intSelStart As Integer
-
Private intSelLength As Integer
-
-
Private Sub MeetingNotes_Enter()
-
-
If Len(MeetingNotes.Text) = 0 Then
-
MeetingNotes.Text = "•" & Chr$(2)
-
MeetingNotes.SelStart = 3 ' Next Line position after space
-
End If
-
-
End Sub
-
-
Private Sub MeetingNotes_Exit(Cancel As Integer)
-
-
If Len(MeetingNotes.Text) > 2 Then ' Need as least "•" & Chr$(2)
-
If Right(MeetingNotes.Text, 2) = "•" & Chr$(2) Then
-
MeetingNotes.Text = Left(MeetingNotes.Text, Len(MeetingNotes.Text) - 2)
-
End If
-
End If
-
-
End Sub
-
-
Private Sub MeetingNotes_KeyDown(KeyCode As Integer, Shift As Integer)
-
-
If KeyCode = 13 And Shift = acShiftMask Then 'Shifted Return
-
intSelStart = MeetingNotes.SelStart
-
KeyCode = 0
-
MeetingNotes.Text = Left(MeetingNotes.Text, intSelStart) & vbCrLf & "•" & Chr$(2) & Mid(MeetingNotes.Text, intSelStart + 1)
-
MeetingNotes.SelStart = MeetingNotes.SelStart + intSelStart + 4
-
End If
-
-
End Sub
-
-
Private Sub MeetingNotes_MouseUp(Button As Integer, Shift As Integer, x As Single, Y As Single)
-
-
'set variables after making selection and releasing mousebutton
-
intSelStart = MeetingNotes.SelStart
-
intSelLength = MeetingNotes.SelLength
-
-
End Sub
A real bu..er to get to work.
Phil
Luk3r,
Thanks! The syntax was just slightly different but it pointed me in the right direction. Here's what I used
[Meeting_Notes.SelStart = Len(Meeting_Notes.Text) + 1]
Thanks PhilOfWalton but I used the other suggestions as it was simpler to add the line of code.
Just thought I would point out that Luk3r's method only adds the bullet at the end of the notes. The method I suggested allows the addition of a new bulleted line in the middle of existing text. Additionally I don't think there is a space between the bullet and the first word in the line.
It's up to you which you use.
Phil
Actually I see what you're saying. I tried your method and although longer, it works! Thanks.
Always best to have code that works rather than the shortest code that almost works.
Also useful to have the Return key (Chr$(13)) working normally so that you can insert blank lines between bullet points.
I have revised the OnExit code, because what I sent you will only remove one "spare" bullet at the end of your text. This code removes all the spare bullets. - Private Sub MeetingNotes_Exit(Cancel As Integer)
-
-
If Len(MeetingNotes.Text) > 2 Then ' Need as least "•" & Chr$(2)
-
Trim (MeetingNotes)
-
Do Until Right(MeetingNotes.Text, 2) <> "•" & Chr$(2)
-
MeetingNotes.Text = Left(MeetingNotes.Text, Len(MeetingNotes.Text) - 2)
-
Trim (MeetingNotes)
-
Loop
-
End If
-
-
End Sub
Glad to be of help
Phil
Sign in to post your reply or Sign up for a free account.
Similar topics
by: leegold2 |
last post by:
General DB questions,
Why do we use null values? Why is it better than an empty field?
What would be a real life situation were nulls are important to have?
If I have a paragraph of text in a...
|
by: adrian |
last post by:
hi all
this is my first post to this group, so pls bear with me while i try
to make some sense.
i am trying to create a sproc which uses dynamic sql to target a
particuar table eg. '.' and...
|
by: Adam |
last post by:
I have an ASP page that will take form info that a user has entered,
then save it into SQL server, and retrive and display the info on
another page. My problem is with long text data (10,000 bytes...
|
by: Adnan Jamil |
last post by:
Hi Guys,
I have editing a SQL Server table field that have long text data. I am
updating some text in this field. How can I update this field instead
of re-write all text. With the Select...
|
by: GeneSZ |
last post by:
How can I make a stored procedure which has a output parameter with
text data type? My procedure is:
CREATE PROCEDURE try
@outPrm text Output
AS
select @outPrm =(select field1 from...
|
by: Bart Van der Donck |
last post by:
Alan wrote:
> Just how big a file can the Text data type contain (in
> kilobytes or Megabytes)? How big a file can a MediumText
> data type contain (in kilobytes or Megabytes)?
'Text' = 64 KB...
|
by: Jacky11 |
last post by:
When combining in a query a field with MEMO Data type and a field with
TEXT Data type like this
Caption: ! & !
The query will not Display/Export more than 256 characters.
The field is a Memo...
|
by: selacika |
last post by:
Hi all;
My question is about how to get non-font information part of a field of text data type using an sql sentence. Shortly how to get pure info from a text data type field.
Example:
Value of...
|
by: =?Utf-8?B?U2FyYWggVw==?= |
last post by:
Hello,
How can I read data field from an oracle procedure with 'long-raw' data type
, using oracle client data adapter?
I tried that:
objPic = New clsPersInfoDT
vCParam1 = New...
|
by: sillyr |
last post by:
Hi - I use Access 2007. I have a two data fields that I would like to add together in a query and then have the query sum the data for the entire table. The problem is that one of the data fields...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
| |