Excel vba - command depending on previous command - variables

Firstly I am new to vba, and in the course of learning have learned a ton from searching this site. Unfortunately this time no success.
I do not know how to tackle this.
My "home" userform has 6 command buttons with no caption to them (empty).
On pressing any one of these, a "names" userform is opened, with 10 command buttons - each is captioned with a different persons name.
I want the chosen perdons name assigned to the caption of the command button that triggered "names" to appear.
On each form I have placed a label. This label's caption changes to the caption of tge command button clicked.
Options I have considered:
1. Multiple multiple IF statements
2. Assigning variables - cant figure out what to assign
I can post my code, but as i do not know where to begin I don't think it would be to much use.

Managed to figure it out!
Made a module with if statments.
Called it from "names" every time a name is chosen.
By doing this no need for writing the same code over again.

Related

Why would an Access 2010 form button with an embedded "openreport" macro and a "where" filter, stop working until I add a new button?

I decided to "tweak" an existing database to further manage multiple sources of income.
I copied the working database and created a "modification copy", just in case I messed things up horribly.
In the modified version, I have a button on a form (in fact, two different buttons with similar macro properties, just directed to do the same function to different reports.
The properties are your standard macro with an openreport, and a "where" condition.
Here's the problem. The macro has worked in the past, and continues to work on my "pre-modification" operating database.
On the modified database, after ensuring all the parameter elements are entered correctly, I can change the "view" to report view, and the macro seems to work just fine until I close the database.
As soon as I open the database, the buttons produce an error. See pic below.
The only way I seem to be able to resolve this odd button macro issue is by going into design view and adding a new button. I've discovered...I don't even need to embed a macro, just adding a new button seems to renew the macro operation...until I close and reopen the database. Then, I have to add a new button again to get the open database's macro to operate.
I can delete the new button added, and still have the macro buttons work, until I close and open the tweaked database.
I have zero VBA coding knowledge. I use Access's macro building tools and typically have to visit sites like this if I need to learn a new "trick" to get my database and it's various tools to do something.
I recently explored with the "subform" that can be seen above in the open form pic with the error message. My guess is that maybe that subform is somehow causing my macros to continuously fail???
Thanks for any help!

VBA MSHTML TextInput Click Failed

I've worked on multiple web-scraping projects using Excel VBA before, but I haven't encountered this problem before. I've been googling the issue for the past few hours, but I haven't found a solution yet.
Scenario:
My webpage consists of a list-box and a text box that acts as a filter/search. Unfortunately, I can't disclose the webpage information, but somewhere in the list box elements I saw the word "JQuery". After creating an HTMLInputElement, I set it to text box object and changed its value to "TEXT". I expected the list to get update, but nothing happened. I tried to use different approaches, but they all failed.
Text_Field.Focus
Text_Field.FireEvent "onclick"
Text_Field.Value = "TEXT"
Text_Field.Click
I managed to put the text in the text box, but the clicking part does not work. When I do it manually, as soon as I type the phrase into the text box, the list gets updated immediately. Any thoughts or suggestions?
I tried to simulate the "enter key" press, but it didn't work either.
Your help will be appreciated.
Best,
Arman
Event won't fire when you operate elements programmatically. you have to simulate the events too, using document.createEventObject/inputElement.fireEvent (IE8 or lower) or document.createEvent/inputElement.dispatchEvent (IE9+).
What event you need to fire depends on what the script is interested in (onkeypress, onblur, onpaste, etc).

Changing ActiveX Component Name Properties Dynamically in Word

I am trying to develop a dynamic user form in a Word document that will create an ActiveX radio button with a generic name and then rename that created radio button to make it have a specific number based on its location in the form.
So far I believe I have all the components to write the code because I am able to create the button. I create the button by using VBA to import a quick part that has the radio button with a defined radioButtonX name and I am able to change the name property of that radio button to radioButton1 for example. The problem that I am running into is that my code will insert the quick part with the generic radioButtonX name and then fail to change the radio button name because it says that radioButtonX does not exist. However, I can manually run the second part of the code after radioButtonX has been inserted and I am able to successfully change the radio button name giving me the end result that I am looking for in two separate steps.
I am a self taught VBA scripter for the last year so I am far from an expert at coding. A few of the strategies that I have taken so far were to:
Put in waits (thinking that pausing the script would give the script time to recognize the new radio button)
Separated the code into different subs having one sub create the radio button and then call a sub to change the name (hoping this would update VBA)
Separated the code into different modules having one modules create the radio button and then call a modules to change the name (hoping this would update VBA)
I was hoping for some advice, strategies, or sample codes that I can use to get VBA to recognize the new radio button that I have inserted while the code was running. Another thought that I had was maybe there is a command that exists that will have VBA refresh its knowledge of variables, but I have not have any luck finding something like that in my web searches to this point.
I tried to simplify the code that I was working on and pull out the code that would perform the function that I was requesting. Running the simpler code was successful and listed below.
Private Sub AddRadioButton()
Selection.TypeText Text:="TestRadioButton"
Selection.Range.InsertAutoText
ActiveWindow.View.ShowXMLMarkup = wdToggle
ChangeButtonName
End Sub
Private Sub ChangeButtonName()
ThisDocument.radioButtonX.Name = "radioButton1"
End Sub
For this script to work you must create a quick part or a radio button that is named TestRadioButton. I think now the root issue has to deal with timing that looked like it wasn't working because the script that this code came from is using a quick part with multiple generic radio buttons in it so the script executing does not recognize the new radio buttons while running.

VBA: Events for several dynamically added buttons

I am adding several CommandButtons dynamically to my user form. To assign code, I used the answer of this question: Assign code to a button created dynamically
However, I need to determine which button has been clicked. They all do have different names. Therefore, my initial idea was to get the name of the clicked button in the CmdEvents_Click() procedure. However, I have not found a solution how to do that.
Does anyone have a solution how to trigger button specific events?
Add the Name of the new command e.g. like ctl_Command.Name = "name_" & i
Then in the CmdEvents_Click just use CmdEvents.Name.

How to use Mouseout Function in VBA with a condition Check?

Hi I have a VBA application with a combobox selection option.One of the combobox option is Other which when user select that option an invisibled label will pops up and prompt the user to fill the txtOther control.now my question is how I can get rid of the prompted label and make it to invisible after user fill the txtOther and move(focused)in other control?
here is a shot of my app:
Thanks for your time and help
It depends on how often or when you want the check to be done. I couldn't find a good reference to show you all of this, but you can view your VBE.
Within the code behind your userform you can use events for the text box.
If you want the check done every time you leave the text box:
Use the TextBox_Exit event.
If you want it to fire whenever the contents are changed, used TextBox_Change. There's lots of options, but based on your explanation I'd probably use Exit.
This answer shows some syntax examples for using the Textbox_Exit event.