473,326 Members | 2,095 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Automatic Bullets for Textbox with Long Text Data Type

12
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]
Sep 25 '18 #1

✓ answered by Luk3r

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:
Expand|Select|Wrap|Line Numbers
  1. 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.

Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  2.  
  3.     Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
  4.         If TextBox1.Text.Length = 1 And TextBox1.Text <> "•" Then
  5.             TextBox1.Text = TextBox1.Text.Insert(0, "•")
  6.             TextBox1.SelectionStart = TextBox1.Text.Length + 1
  7.         End If
  8.     End Sub
  9.  
  10.     Private Sub TextBox1_KeyUp(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyUp
  11.         Dim KeyCode As Integer = e.KeyCode
  12.         If KeyCode = 13 Then
  13.             TextBox1.Text = TextBox1.Text & "•"
  14.             TextBox1.SelectionStart = TextBox1.Text.Length
  15.         End If
  16.     End Sub
  17.  
  18. End Class

7 1579
Luk3r
300 256MB
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:
Expand|Select|Wrap|Line Numbers
  1. 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.

Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  2.  
  3.     Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
  4.         If TextBox1.Text.Length = 1 And TextBox1.Text <> "•" Then
  5.             TextBox1.Text = TextBox1.Text.Insert(0, "•")
  6.             TextBox1.SelectionStart = TextBox1.Text.Length + 1
  7.         End If
  8.     End Sub
  9.  
  10.     Private Sub TextBox1_KeyUp(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyUp
  11.         Dim KeyCode As Integer = e.KeyCode
  12.         If KeyCode = 13 Then
  13.             TextBox1.Text = TextBox1.Text & "•"
  14.             TextBox1.SelectionStart = TextBox1.Text.Length
  15.         End If
  16.     End Sub
  17.  
  18. End Class
Sep 25 '18 #2
PhilOfWalton
1,430 Expert 1GB
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.

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private intSelStart As Integer
  5. Private intSelLength As Integer
  6.  
  7. Private Sub MeetingNotes_Enter()
  8.  
  9.     If Len(MeetingNotes.Text) = 0 Then
  10.         MeetingNotes.Text = "•" & Chr$(2)
  11.         MeetingNotes.SelStart = 3           ' Next Line position after space
  12.     End If
  13.  
  14. End Sub
  15.  
  16. Private Sub MeetingNotes_Exit(Cancel As Integer)
  17.  
  18.     If Len(MeetingNotes.Text) > 2 Then                  ' Need as least "•" & Chr$(2)
  19.         If Right(MeetingNotes.Text, 2) = "•" & Chr$(2) Then
  20.             MeetingNotes.Text = Left(MeetingNotes.Text, Len(MeetingNotes.Text) - 2)
  21.         End If
  22.     End If
  23.  
  24. End Sub
  25.  
  26. Private Sub MeetingNotes_KeyDown(KeyCode As Integer, Shift As Integer)
  27.  
  28.     If KeyCode = 13 And Shift = acShiftMask Then         'Shifted Return
  29.         intSelStart = MeetingNotes.SelStart
  30.         KeyCode = 0
  31.         MeetingNotes.Text = Left(MeetingNotes.Text, intSelStart) & vbCrLf & "•" & Chr$(2) & Mid(MeetingNotes.Text, intSelStart + 1)
  32.         MeetingNotes.SelStart = MeetingNotes.SelStart + intSelStart + 4
  33.     End If
  34.  
  35. End Sub
  36.  
  37. Private Sub MeetingNotes_MouseUp(Button As Integer, Shift As Integer, x As Single, Y As Single)
  38.  
  39. 'set variables after making selection and releasing mousebutton
  40.     intSelStart = MeetingNotes.SelStart
  41.     intSelLength = MeetingNotes.SelLength
  42.  
  43. End Sub
A real bu..er to get to work.

Phil
Sep 25 '18 #3
Merlene
12
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]
Sep 27 '18 #4
Merlene
12
Thanks PhilOfWalton but I used the other suggestions as it was simpler to add the line of code.
Sep 27 '18 #5
PhilOfWalton
1,430 Expert 1GB
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
Sep 27 '18 #6
Merlene
12
Actually I see what you're saying. I tried your method and although longer, it works! Thanks.
Sep 28 '18 #7
PhilOfWalton
1,430 Expert 1GB
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.

Expand|Select|Wrap|Line Numbers
  1. Private Sub MeetingNotes_Exit(Cancel As Integer)
  2.  
  3.     If Len(MeetingNotes.Text) > 2 Then                  ' Need as least "•" & Chr$(2)
  4.         Trim (MeetingNotes)
  5.         Do Until Right(MeetingNotes.Text, 2) <> "•" & Chr$(2)
  6.             MeetingNotes.Text = Left(MeetingNotes.Text, Len(MeetingNotes.Text) - 2)
  7.             Trim (MeetingNotes)
  8.         Loop
  9.     End If
  10.  
  11. End Sub
Glad to be of help

Phil
Sep 28 '18 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
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...
5
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...
3
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...
1
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...
1
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...
0
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...
0
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...
0
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...
0
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...
9
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...
0
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
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...
0
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...
0
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...
1
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)...
1
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
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

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.