Input Mask on a text field

  • Thread starter Aron M via AccessMonster.com
  • Start date
A

Aron M via AccessMonster.com

Does anyone know if there is any way to set up an input mask that won't allow
the user to put a carriage return into a text field? They have to be able to
put as many alpha characters or numeric chars as they like. Or if anyone has
a better way to do this, I'd appreciate it.

Thanks.
 
A

Al Camp

If your field's EnterKeyBehaviur is set to Default, the Enter key would act
like a tab to the next field.

I came up with this solution to just ignore the EnterKey. I'm sure there's
a more elegant solution, but this appears to work just fine.
In the KeyPreview event for your field, place this code...
If KeyAscii = vbKeyReturn Then
KeyAscii = vbKeyControl
End If
The Control key doesn't do anything, so the user can just keep on typing.
 
A

Aron M via AccessMonster.com

Al said:
If your field's EnterKeyBehaviur is set to Default, the Enter key would act
like a tab to the next field.

I came up with this solution to just ignore the EnterKey. I'm sure there's
a more elegant solution, but this appears to work just fine.
In the KeyPreview event for your field, place this code...
If KeyAscii = vbKeyReturn Then
KeyAscii = vbKeyControl
End If
The Control key doesn't do anything, so the user can just keep on typing.
Does anyone know if there is any way to set up an input mask that won't
allow
[quoted text clipped - 5 lines]

Thank you for the reply Al. The problem I'm having is the user is pressing
the Control Key along with the Enter Key and it's creating a line break when
we export the data to a .csv file so your solution may work. What is the
KeyPreview event? I don't see it listed in the properties under the event
tab.

Thanks again,
Aron
 
A

Aron M via AccessMonster.com

Aron said:
If your field's EnterKeyBehaviur is set to Default, the Enter key would act
like a tab to the next field.
[quoted text clipped - 11 lines]
Thank you for the reply Al. The problem I'm having is the user is pressing
the Control Key along with the Enter Key and it's creating a line break when
we export the data to a .csv file so your solution may work. What is the
KeyPreview event? I don't see it listed in the properties under the event
tab.

Thanks again,
Aron

I ended putting the following code in the KeyDown event.

If KeyCode = 13 And Shift = 2 Then
KeyCode = 0
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top