tags:

views:

1170

answers:

6

Is there a way to disable entering multi-line entries in a Text Box (i.e., I'd like to stop my users from doing ctrl-enter to get a newline)?

A: 

not entirely sure about that one, you should be able to remove the line breaks when you render the content though, or even run a vbscript to clear it out, you just need to check for chr(13) or vbCrLf.

Mauro
Not quite what I wanted. It means that I'm having to monkey with the user's data in the background (not WYSIWYG) or be throwing errors that I would have put a lot of explanation behind. Thanks though.
CodeSlave
+2  A: 

The way I did it before (and the last time I worked in Access was around '97 so my memory is not so hot) was raising a key-up event and executing a VBA function. It's a similar method to what you do with an AJAX suggest text box in a modern webform application, but as I recall it could get tripped up if your Access form has other events which tend to occur frequently such a onMouseMove over the entire form object.

Ian Patrick Hughes
Again, the KeyUp event first with each keystroke, and this can lead to flickering screen display. And it's simply inefficient -- the best event for this is still the AfterUpdate event of the control you're using to edit the memo because it fires only once.
David-W-Fenton
That comment should read: The KeyUp event FIRES with each keystroke...
David-W-Fenton
+2  A: 

I was able to do it on using KeyPress event. Here's the code example:

Private Sub SingleLineTextBox_ KeyPress(ByRef KeyAscii As Integer)
    If KeyAscii = 10 _
        or KeyAscii = 13 Then
            '10 -> Ctrl-Enter. AKA ^J or ctrl-j
            '13 -> Enter.      AKA ^M or ctrl-m
        KeyAscii = 0  'clear the the KeyPress
    End If
End Sub
CodeSlave
This is not by any means the best solution, because it uses the wrong event, and fires with each keystroke. The control's AfterUpdate event is much more appropriate, and fires only once.
David-W-Fenton
It's working for me. No screen flicker. And in this case I want to prevent the bad input initially RATHER than try and sift it out later and either give the user an obtuse error or change their input on them.
CodeSlave
A: 

If you don't want an event interfering, you can set up the Validation Rule property for the textbox to be

NOT LIKE "*"+Chr(10)+"*" OR "*"+Chr(13)+"*"

You will probably also want to set the Validation Text to explain specifically why Access is throwing up an error box.

Jason Z
Not quite what I wanted either, user never seem to understand the validation text. Thanks though.
CodeSlave
A: 

Using the KeyPress event means that your code will fire every time the user types. This can lead to screen flickering and other problems (the OnChange event would be the same).

It seems to me that you should use a single event to strip out the CrLf's, and the correct event would be AfterUpdate. You'd simply do this:

  If InStr(Me!MyMemoControl, vbCrLf) Then
     Me!MyMemoControl = Replace(Me!MyMemoControl, vbCrLf, vbNullString)
  End If

Note the use of the Access global constants, vbCrLf (for Chr(10) & Chr(13)) and vbNullString (for zero-length string).

Using a validation rule means that you're going to pop up an ugly error message to your user, but provide them with little in the way of tools to correct the problem. The AfterUpdate approach is much cleaner and easier for the users, seems to me.

David-W-Fenton
Considering you are handling it in the front end, there's no harm in adding the Validation Rule in the database as well. It might even be a boon e.g. when a user tries to access the data via Excel, as they always do sooner or later :)
onedaywhen
But if you put in the validation rule, you have to use the BeforeUpdate event instead of AfterUpdate. Otherwise, you'll pop the Jet data error about the validation rule violation.
David-W-Fenton
I understand your argument. However, in practice I get no screen flicker with my method. Additionally, scrubbing CrLf's out after the user has made updates will change the way the data is represented from the way that they entered it. Which in turn will lead to more squawking by the users. I prefer that when they enter data, "what they see is what they get".
CodeSlave
A: 

I am having problems with jpeg files exported from Lightroom 2.2 http://www.ebook-search-queen.com/ebook/ligh/lightroom-2.2.all.html . I dont think ImageGetExifMetadata working properly for LR images. I can see the all exif information with a different programs. One of the errors:"Element Focal Plane Y Resolution is undefined in a CFML structure referenced as part of an expression. ". "Element Focal Plane Y Resolution" is there but CF can't read it. I have tried all sorts with no luck.On the other hand it works for non LR jpg images. Any ideas?

Noo idea... have you considered starting a new question? Just click the Ask Question button, top right hand corner of the page.
CodeSlave