Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Difficulty restricting characters


I've used the following code to try and restrict certain characters to a
textbox:

Private Sub TextBox2_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Select Case KeyAscii
Case Asc(".")
If InStr(1, Me.TextBox1.Text, ".") 0 Then
KeyAscii = 0
End If
End Select
End Sub

The period is not the only character I'm trying to restrict but it is
one of them. Whenever I've tried to use 'Select Case', the code never
seems to do anything... at all. The Textbox2 is used as the savename so
I can't allow any weird characters to get typed in.

Can anyone help me out regarding this?

Thanks,

Kartune85


--
kartune85
------------------------------------------------------------------------
kartune85's Profile: http://www.excelforum.com/member.php...o&userid=35586
View this thread: http://www.excelforum.com/showthread...hreadid=569743

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 459
Default Difficulty restricting characters

"kartune85" ha
scritto nel messaggio
...

I've used the following code to try and restrict certain characters to a
textbox:

Private Sub TextBox2_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Select Case KeyAscii
Case Asc(".")
If InStr(1, Me.TextBox1.Text, ".") 0 Then
KeyAscii = 0
End If
End Select
End Sub

The period is not the only character I'm trying to restrict but it is
one of them. Whenever I've tried to use 'Select Case', the code never
seems to do anything... at all. The Textbox2 is used as the savename so
I can't allow any weird characters to get typed in.

Can anyone help me out regarding this?


Hi Kartune,

Instead of a text box to input the filename, you could try to use the Excel
Save As window:

Application.Dialogs(xlDialogSaveAs).Show


--
Hope I helped you.

Thanks in advance for your feedback.

Ciao

Franz Verga from Italy


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Difficulty restricting characters


With the SaveAs dialog, I still can't restrict certain characters. I'v
made the form for end-users so I have to try and make it easy to us
and idi0t-proof.

I ended up using:

If InStr(1,TextBox2.Text,".") 0 then
MsgBox "Invalid characters, please re-enter."
cancel = true
Else...

The only problem is that I repeated InStr(...) for each individua
character and added them up in a variable. (SearchStr = InStr(...".")
InStr(..."/")...)

Thanks anyway, but if anyone knows an easier way, I'm open fo
suggestions.

Kartune8

--
kartune8
-----------------------------------------------------------------------
kartune85's Profile: http://www.excelforum.com/member.php...fo&userid=3558
View this thread: http://www.excelforum.com/showthread.php?threadid=56974

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Difficulty restricting characters

I'd go with Franz's suggestion; let the OS decide if the filename is valid
or not.

On Error resume next
WB.SaveAs "C:hhhh/\\:::tt.txt.txt.xls"
If Err.number0 then
'deal with the problem

By the way a file name of MyExcelFile.txt.xls is a valid name

NickHK

"kartune85" wrote
in message ...

With the SaveAs dialog, I still can't restrict certain characters. I've
made the form for end-users so I have to try and make it easy to use
and idi0t-proof.

I ended up using:

If InStr(1,TextBox2.Text,".") 0 then
MsgBox "Invalid characters, please re-enter."
cancel = true
Else...

The only problem is that I repeated InStr(...) for each individual
character and added them up in a variable. (SearchStr = InStr(...".") +
InStr(..."/")...)

Thanks anyway, but if anyone knows an easier way, I'm open for
suggestions.

Kartune85


--
kartune85
------------------------------------------------------------------------
kartune85's Profile:

http://www.excelforum.com/member.php...o&userid=35586
View this thread: http://www.excelforum.com/showthread...hreadid=569743



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Restricting Number of characters in a cell Colin Hayes Excel Worksheet Functions 9 September 11th 09 01:45 PM
Difficulty cleaning some char(63) characters Raj[_2_] Excel Worksheet Functions 1 May 8th 09 07:31 PM
restricting use of certain characters Rob Excel Discussion (Misc queries) 4 June 8th 06 01:07 AM
restricting input characters Bri[_3_] Excel Programming 4 May 9th 06 11:26 AM
Restricting Characters in a cell. R Bitterman Excel Programming 3 October 13th 05 02:47 PM


All times are GMT +1. The time now is 07:18 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"