Set vb6 form to instance of a hardcoded form - vb6

I have a 2 Forms. Form1 opens Form2. Form2 after clicking a value, sends that value to a textbox located in Form1. It is hardcoded so that inside Form2 it explicitly states Form1.txtbox.Text = "Whatever i clicked" Form2 then closes and I am now sitting at Form1, however the txtbox.text has not received the new value from Form2.
In the immediate window Form1.txtbox.text = "Whatever I clicked" is alright, however txtbox.text = "" within the context of Form1 is blank.
I opened Form1 using Forms.Add("Form1") now is there anyway to set this instance of the form into the hardcoded instance? I imagine the error is occurring because Forms.Add("Form1") creates an instance of that form while Form1.show is the actual form. Is there anyway to match these two up to be the same object?

The best solution for this is using what Bob77 said and applying it to the form.
When loading Form1 using the Forms.Add("Form1") method if you were to implement Set Form1 = Me in Form_Load it will now set the reference of Me to be Form1 so that when you made direct changes to it in Form2 using Form1.Foo = "bar" then it would work.

Related

Problem on applying script when i send the email

Does anyone know how to trigger VBA when i sent out an email.
I tried to look for the option from Rule Wizard on "Apply rule on message i send" but there is script option.
Cheers
Of course, you may assign a VBA sub to run when your rule is triggered. The sub should take a single argument which represents the item being sent:
Public Sub Test(item as Outlook.MailItem)
' run your code here
End Sub
You may add an event handler to the ItemSend event of the Application class. It is fired whenever an Microsoft Outlook item is sent, either by the user through an Inspector (before the inspector is closed, but after the user clicks the Send button) or when the Send method for an Outlook item, such as MailItem, is used in a program.
Public WithEvents myOlApp As Outlook.Application
Public Sub Initialize_handler()
Set myOlApp = Outlook.Application
End Sub
Private Sub myOlApp_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim prompt As String
prompt = "Are you sure you want to send " & Item.Subject & "?"
If MsgBox(prompt, vbYesNo + vbQuestion, "Sample") = vbNo Then
Cancel = True
End If
End Sub
You write an event procedure (also known as an event handler) to respond to events that occur in Microsoft Outlook. For example, you can write an event procedure that automatically maximizes the explorer window when Outlook starts.
Events are associated with particular objects. The Application object is the topmost object, and is always available (that is, it does not have to be created). You can add an Application event procedure in the ThisOutlookSession module window simply by selecting Application in the left list and then selecting the event in the right list.

VB.NET pas textbox value in windows form to textbox in ASP page

I currently develop a POS system with VB.NET 2017. In the form I work on (called frmProcessCheckOut), I have a textbox where the user enters the amount to charge on Visa. I have an ASP page that has a textfield as well. Is there a way to have a button on the windows form that when I click on it, it puts the value of the textbox in the textfield of the ASP page?
Thank you.
I would do it this way.
1) In Button Click Event, I will trigger the Internet Explorer process as the same time opening my website URL and passing the text value into web parameter, ex. refID
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Process.Start("C:\Program Files\Internet Explorer\iexplore.exe", "http://mywebsite.com?refID=" & TextBox1.Text)
End Sub
2) Inside the ASPX page Load Event, you can read Page Request and do your needed actions to it.
If Request("refID") = Nothing Then
'You didn't pass any values, or TextBox1.text was empty.
Else
'TextBox1 has some text, do some actions.
End If

VB6 _Validation event not firing when tabbing to Cancel button with CausesValidation = False

I have a situation similar to the following simplified description:
A form with a TextBox (call it txtQty) in which a user can enter an integer. The event txtQty_Validate is used to validate the user input and force them to correct any errors before changing focus. This works great with all other controls on the form except for said txtQty. I assume that this is because the Cancel button on the form has the property CausesValidation necessarily set to false; thus when the user Tabs from txtQty to the Cancel button (whose TabIndex is next) it does not appropriately trigger the txtQty_Validation event.
My first instinct was to simply go to the txtQty_KeyPress event (which I am already using to make the RETURN key behave as TAB key) and capture the TAB key and temporarily toggle the CausesValidation property to allow the txtQty_Validation event to fire. However, it seems as though capturing the TAB key is not as easy as I had thought it would be.
Any suggestions? I assume that this cannot be the first time anybody creating a Form has come across such a situation.
Thanks
You could try this in the Cancel GotFocus event.
Dim b As Boolean
Call txtQty_Validate(b)
If b Then txtQty.SetFocus
Assuming you have something like this
Private Sub txtQty_Validate(Cancel As Boolean)
If Not IsNumeric(txtQty.Text) Then
Cancel = True
End If
End Sub

Add event listener to Excel Textbox (lose focus)

I need to fire an sub or a command when a user is done using a text box in Excel.
I have tried using the AfterUpdate() event and the LoseFocus() event like this:
Public Sub Kommentar_AfterUpdate()
MsgBox ("Hurray")
End Sub
The text box is named Kommentar and is inside the sheet Radio. Also, where is the code supposed to be written? i have tried placing it in code sheet for the Radio sheet, and in a separate module.
Any tip, hint or answer is appreciated!
For embedded ActiveX Excel control - add the following in the sheet mobile in VBA. TextBox1 is the name of the control:
Private Sub TextBox1_LostFocus()
End Sub
For userform - use the following where Textbox1 is the name of your textbox:
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
End Sub
You can set the Cancel bool to True if you do not want to lose focus from the textbox. In addition the code is placed within the UserForm >> Right Click >> View Code.

Multiple forms on one page

For example if i have 3 forms on one page, how can i check in my view function which form was posted?
form1 = FormClass1
form2 = FormClass2
form3 = FormClass3
All of them will be posted unless you put them in separate form tags with separate submit buttons.

Resources