By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,937 Members | 1,532 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,937 IT Pros & Developers. It's quick & easy.

Multiline textbox: next line undone when control is locked!

P: 5
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
Share this Question
Share on Google+
10 Replies

P: 675
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

Expert Mod 15k+
P: 31,769
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

P: 675
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

P: 5
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

Expert Mod 15k+
P: 31,769
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

P: 5
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

Expert Mod 15k+
P: 31,769
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

P: 5
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

P: 5

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

Expert Mod 15k+
P: 31,769
I think that's only available in Access 2007. Sorry I have no knowledge of that.
Jul 15 '10 #11

Post your reply

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