View Full Version : [SOLVED:] If textbox contains X run Y on button press?
totalnoob
08-31-2017, 07:14 AM
Hello everyone,
I've been googling furiously for the last 40 minutes and can't figure this out. I am creating a simulation for training of a web based tool we use in my office. It is a very simple tool comprised of about 4 pages with basic buttons and prompts. I have everything working except for one piece.
On the first page of our tool, you search for a user using a 4-digit identifier. I have a text box to type the identifier as well as a button that moves you to the next page in the tool. However, I cannot for the life of me figure out how to make the button check the identifier. We have a couple different situations that I want to show, and each would need a different identifier.
Basically. If X is in the text box, I want the button to go to slide Y, but if Y is in the text box I want the button to go to slide Z. Does that make sense?
Any help would be greatly appreciated.
Show us the code you have now.
Copy the code in the VBA Editor, then in your post here, Click the # icon and then press Ctrl+V
totalnoob
08-31-2017, 11:33 AM
I was able to get one scenario working. Here is what I did. However I now am having issues trying to create multiple scenarios. I was planning on just using ElseIf statements, but it keeps giving me errors that I'm trying to work through. Is there a more efficient way to create multiple options than with ElseIf statements?
Sub ifthen()
If Slide1.TextBox21.Value = "napr" Then
With Application
.Presentations(1).SlideShowSettings.Run
With SlideShowWindows(1).View
.GotoSlide 2
Exit Sub
End With
End With
End If
That's not much code for me to go on... For one thing, Where's the button?
But here (http://www.vbaexpress.com/forum/showthread.php?60576-Hide-Worksheets-dependant-on-domain-name&p=368322&viewfull=1#post368322) is an example of one way to make selections based on multiple options.
John Wilson
09-01-2017, 09:25 AM
It's VERY unclear what you need.
Is this the scenario or is it something else entirely??
A slide show is RUNNING
There is an activX textbox the user can type a four digit number into based on the entry it jumps to a specified slide.
If it is something else a clear explanation will help!
totalnoob
09-01-2017, 02:20 PM
My apologies if I was unclear in what I was asking.
I have a PowerPoint open with a screenshot of the first page of our online password reset tool. On that page there is a text entry field (where you would type in the 4-digit identifier of the user) as well as a search button.
My first issue was trying to figure out how to make it so if I entered in a specific identifier into the text box and then hit search, it would go to a specific slide.
I don't think what I did was very efficient, but it is working now. I used an invisible action button over the search button on the screenshot and put a text box over the spot where the user would normally type. I then worked my way through to the code I had up top. Now when I search for "NAPR" it goes to a specific slide.
The next problem I had was how to have it go to a different specific slide when I type in something else, "Fo0d" or "CAR5" for example. I was able to get this working as well pretty quickly, however I doubt any of this was efficient. This is what my code looks like now:
Sub ifthen()
If UCase(Slide1.TextBox21.Text) = "FO0D" Then
With Application
.Presentations(1).SlideShowSettings.Run
With SlideShowWindows(1).View
.GotoSlide 2
End With
End With
End If
If UCase(Slide1.TextBox21.Text) = "CAR5" Then
With Application
.Presentations(1).SlideShowSettings.Run
With SlideShowWindows(1).View
.GotoSlide 20
End With
End With
End If
Exit Sub
End Sub
Does that clear things up a bit? Again, sorry for the confusion. I'm totally new to this whole thing and thought I was providing all necessary information.
Much better
Sub ifthen_by_vbaexpress()
Dim SlideNum As Long 'You need to verify that Slide numbers are Long Type, 'cuz I don't know.
Select Case UCase(Slide1.TextBox21.Text)
Case "FO0D": SlideNum = 2
Case "CARS": SlideNum = 20
Case "TOTALNOOB": SlideNum =99
Case "SAMT": SlideNum = 999
Case "VBAEXPRESS.COM": SlideNum = 9999
Case Else: Exit Sub
End Select
With Application
.Presentations(1).SlideShowSettings.Run
With SlideShowWindows(1).View
.GotoSlide SlideNum
End With
End With
End Sub
John Wilson
09-02-2017, 03:04 AM
20235
If you can type into an ActivX box you are ALREADY in show mode so the line .Presentations(1).SlideShowSettings.Run is not needed.
The attached file shows how you might do this
Right click the box > View Code to see the code which should be easy to adapt
Test by entering ABC or XYZ in show mode and then ENTER (In the code you need CAPS I think ut you can alter this as in Sam's code
totalnoob
09-05-2017, 06:55 AM
Oh my gosh that is so much cleaner and more efficient!!! Thank you so much!
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.