Hi, i have a text box on a slide, where a user enters a sentance, i would like to prevent the user from entering a , value into.
So far i am using the following code:
Code:
If Slide15.TextBox1.Value = "," Then
MsgBox "Invalid Character Entered. You Cannot Enter , Value.", vbOKOnly, "ERROR"
End If
This displays an error if only a , value is entered, but i need an error to be displayed if the user enters a comma value as part of a sentance, for example "Hi, thank you".
Also, i have code running after this, which takes the user to the next slide, but i only want this part of the code to be run if there is no , value in the textbox.
Now, if there is a , value typed in, i want the code to stop there and not carry on to the bit where the user is taken to the next slide, so that the user can remove the , value from the text box.
Code:
If InStr(Slide15.TextBox1.Value, ",") Then
MsgBox "Invalid Character Entered. You Cannot Enter , Value.", vbOKOnly, "ERROR"
End If
With Application
.Presentations(1).SlideShowSettings.Run
With SlideShowWindows(1).View
.GotoSlide 16
End With
End With
End Sub
If InStr(Slide15.TextBox1.Value, ",") Then
MsgBox "Invalid Character Entered. You Cannot Enter , Value.", vbOKOnly, "ERROR"
Exit Sub
End If
Is there any way in which i could Set the Focus onto the text box where a comma has been typed in, so if the user has typed in a comma in TextBox1 the user will be returned to TextBox1. Also would it be able to highlight the text in the textbox.
Thanks
Last edited by Khadafi; Mar 21st, 2010 at 07:24 AM.
I believe you have access to the textBox events if the textbox is in on a slide (I'm on a mac currently, so I can't check this right now). If so, you can put this code into the KeyPress event for TextBox1, it will prevent them from typing in a comma during entry:
Code:
Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If KeyAscii = 44 Then
Beep
KeyAscii = 0
End If
End Sub
How have you added the textbox? If it is via Menu View~~Toolbars~~>control toolbox then what mark suggested will work or an alternative mentioned below will also work... But then you have to be in Slide Show mode to type in the textbox...
Code:
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, _
ByVal Shift As Integer)
If KeyCode = 188 Then KeyCode = 0
End Sub
However ifyou are adding a textbox from the Drawings toolbar then you can use the code mentioned in your last post or modify the below which will also work...
Code:
Sub Sample()
If InStr(1, ActivePresentation.Slides(15).Shapes("Text Box 1").TextFrame.TextRange, ",") Then
MsgBox "Invalid Character Entered. You Cannot Enter , Value.", vbOKOnly, "ERROR"
Exit Sub
End If
'~~> your code here to run if no comma
End Sub
To highlight the text see this slight modification...
Code:
Sub Sample()
If InStr(1, ActivePresentation.Slides(15).Shapes("Text Box 1").TextFrame.TextRange, ",") Then
MsgBox "Invalid Character Entered. You Cannot Enter , Value.", vbOKOnly, "ERROR"
'~~> Highlight the text...
ActivePresentation.Slides(15).Shapes("Text Box 1").TextFrame.TextRange.Select
Exit Sub
End If
'~~> your code here to run if no comma
End Sub
Last edited by Siddharth Rout; Mar 22nd, 2010 at 03:49 PM.
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread "Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
Hi, i am unable to upload my original presentation, but i have created an example presentation which demonstrates what i want to do.
I have uploaded it.