473,378 Members | 1,451 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,378 software developers and data experts.

Multiline textbox: next line undone when control is locked!

Good day!

I have a form in Access that has a multiple line textbox (I called it cAbnormalities). This text box is populated by the user ONLY through selection of options from combo boxes. I want the selected options to each be in a seperate line, and I don't want the user to be able to edit the textbox without using the combo boxes.

Here is my code when a selection is made from the combo box:
Expand|Select|Wrap|Line Numbers
  1. Me.cAbnormalities.Locked = False
  2. Me.cAbnormalities.SetFocus
  3. Me.cAbnormalities = Me.cAbnormalities & cBoxText
  4. Me.cAbnormalities.SelStart = Nz(Len(Me.cAbnormalities), 1)
  5. SendKeys "{enter}"
  6. SendKeys "{backspace}"
  7. Me.cAbnormalities.Locked = True
If I remove the two lines that lock and unlock the control, then my text is entered in a new line, otherwise the new line is undone! Can someone please help!

Thanks in advance!
Jul 15 '10 #1
10 3750
OldBirdman
675 512MB
Access Help "vb constants" supplies an easy solution. Replace all your code with:
Expand|Select|Wrap|Line Numbers
  1. Me.cAbnormalities = Me.cAbnormalities & cBoxText & vbKeyReturn & vbKeyBack
You needed to unlock the control to use SendKeys, but this is not necessary. SendKeys is not recommended unless there is no other solution, as SendKeys often gives strange results. The assignment will work even with the control locked.
You needed to set SelStart for SendKeys, but no longer necessary.

Welcome to Bytes!
Jul 15 '10 #2
NeoPa
32,556 Expert Mod 16PB
All OB says is correct. I'd do it very slightly differently, but not because his wouldn't work :
Expand|Select|Wrap|Line Numbers
  1. With Me
  2.   .cAbnormalities = .cAbnormalities & _
  3.                     IIf(Len(.cAbnormalities) > 0, _
  4.                         vbNewLine, "") & _
  5.                     cBoxText
  6. End With
I've split lines simply for readability, particularly with our current CODE boxes. It's still a single instruction.
Jul 15 '10 #3
OldBirdman
675 512MB
As usual, NeoPa, efficient & nice code. Does more than the original code does.
My intent was to show where the old code failed, and offer a solution that did exactly what the failed code attempted. As cBoxText is a ComboBox, I assumed that there were no null or zero-length rows. If so, that should be handled elsewhere. The original post gave no indication as to what had triggered the code, nor what validity/error checking had gone before.
As this is the first post by JohannKotzeVet, I did not know his skill level. My response was at the level of the original post.
Jul 15 '10 #4
Thanks for the replies, but it still doesn't work.

The vbKeyReturn command only returns a "13" in the text box.

The vbNewLine command does nothing at all.

I have set the EnterKeyBehaviour as "New Line In Field". I can not find a property that sets the text box to a multiple line box. But if I type within the box and press enter everything works as it should.

Thanks for the help!
Jul 15 '10 #5
NeoPa
32,556 Expert Mod 16PB
OB. Your response was fine and I have abvsolutely no criticism of it. I was merely offering an alternative.

JohannKotzeVet: The vbNewLine command does nothing at all.
I'm a little confused as there is no separate command vbNewLine. Did you copy and paste the code exactly as displayed? The underscore (_) at the end of a line indicates that the line of code should continue onto the next line by the way. Thus lines #2 through #5 are a single statement in my posted code.
Jul 15 '10 #6
Yes, I pasted it exactly as displayed. I then removed all the code around it to see exactly what VbNextLine does.

Expand|Select|Wrap|Line Numbers
  1.  Me.cAbnormalities = Me.cAbnormalities & "Text" & vbNewLine 
The result was a single space after the text. With the next text still produced in the same line.

How can I change that vbReturnKey does not produce an ASCII number but that it represents the actual key pressed?
Jul 15 '10 #7
NeoPa
32,556 Expert Mod 16PB
Try :
Expand|Select|Wrap|Line Numbers
  1. Me.cAbnormalities = Me.cAbnormalities & "Text" & vbNewLine & "New Line"
  2. Debug.Print Me.cAbnormalities
Then copy and paste the results here if you would.
Jul 15 '10 #8
Text
New line

Ok, so how do I fix the textbox window? Thanks! I finally feel there is hope on the horizon! :-)
Jul 15 '10 #9
Great!

I solved the problem by changing the text box's text format from 'Rich Text' back to 'Plain text'. I can live with that, it's not important for me to solve the problem with textbox still using rich text, but it would be nice how I could have solved it.. Any suggestions?

Thanks again! This site is great!

(I'm not a professional programmer so I really appreciate and need the help!)
Jul 15 '10 #10
NeoPa
32,556 Expert Mod 16PB
I think that's only available in Access 2007. Sorry I have no knowledge of that.
Jul 15 '10 #11

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

Similar topics

6
by: Suresh Kumaran | last post by:
Hi All, Does anybody know the sytax in VB.NET to write the contents of a multiline text box to a text file? Appreciate help. Suresh
1
by: Rocketman | last post by:
I am trying to find out when i reach the next line when multiline is switched on and i DON'T PRESS ENTER TO GO TO THE NEXT LINE(lines method is there for that purpose). Is there any other method i...
4
by: Michael C | last post by:
Hi all, I'm trying to add lines to a multiline textbox. Here's what I'd like to end up with in the textbox (as an example): Line1 Line2 Line3 I've tried a couple of methods but nothing...
2
ID94
by: ID94 | last post by:
How do i code next line. ie: when assigning text to a text box?
0
by: CaJack | last post by:
Hi, I’m having trouble with my code and I’m starting to get lost. The Program takes the country that’s been typed in to the textbox and when the query button is clicked the program queries an access...
2
by: Mike | last post by:
I am trying to write a little program for my own use using VB2005 express edition. I have a list of peoples names in a file that I read into an array of strings. I am using a multiline textbox to...
7
by: Anil Gupte | last post by:
I have read a lot about getting lines from a multiline textbox in VB.Net. However, I cannot for the life of me figure out how to write to a multiline textbox. Basically, I have created an array of...
4
by: =?Utf-8?B?R2lkaQ==?= | last post by:
Hi, In multiLine textBox, enter moves to the next line, how can i overwrite it, so enter will move to the next control and ctrl + enter will move to the next line? Thanks, Gidi.
2
by: Nathan Sokalski | last post by:
I have a multiline TextBox that I want to display the text used to create a control in an apsx file. I want each of these to be on a separate line in the TextBox. The only way I know of to place...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.