Outlook form VBScript for controls - forms

I've created an Outlook form with several bound controls. I would like one of the check boxes when checked to make two text areas and their labels visible, then not be visible if the check box is unchecked. The controls that I want to make visible have the initial state of not-visible. I'm stuck on the VBScript syntax. I've been using Sue Mosher's Outlook programming book, but I'm a newby and I'm not getting it. I'd appreciate any help with this. I'm using Outlook 2010 on a Windows 7 machine. Thanks!
Here's my code:
Sub Item_PropertyChange(byVal Name)
Set objInsp = Item.GetInspector
Set objPage = objInsp.ModifiedFormPages("Message")
Set ckWGC = objPage.Controls("ckWGC")
Set lblState = objPage.Controls("lblState")
Set WGCState = objPage.Controls("WGCState")
Set lblCountry = objPage.Controls("lblCountry")
Set WGCCountry = objPage.Controls("WGCCountry")
If ckWGC.Value = True Then
lblState.Visible = True
WGCState.Visible = True
lblCountry.Visible = True
WGCCountry.Visible = True
Else
lblState.Visible = False
WGCState.Visible = False
lblCountry.Visible = False
WGCCountry.Visible = False
End If
End Sub

You would want to handle the CheckBox.Change event to capture when the user has checked or unchecked it.
Private Sub CheckBox1_Change()
End Sub

Related

Why is my Luau code not hiding the GUIs that I tried to hide?

My code is for hiding some GUIs that I don't want to show. (Note that this is Luau, I can't post to DevForums because I am not a member)
This is what I want to hide:
Link here
The code I used was:
local Dialog = false
local Confirm = false
local TalkTo = ""
local ConfirmGUI = script.Parent.Parent.Parent.Parent.ConfirmGUI.ScreenGui -- Avoiding waste of time writing the full directory and having to fail because it's in PlayerGUI
ConfirmGUI.TextButton.Visible = false
ConfirmGUI.TextButton2.Visible = false
ConfirmGUI.TextLabel.Visible = false
ConfirmGUI.TextTitle.Visible = false
The error I keep getting in Developer Console is:
09:04:06.668 ConfirmGUI is not a valid member of PlayerGui "Players.metoplayllol.PlayerGui" - Client - LocalScript:6
09:04:06.668 Stack Begin - Studio
09:04:06.669 Script 'Players.metoplayllol.PlayerGui.DialogGUI.ScreenGui.TextLabel.LocalScript', Line 6 - Studio - LocalScript:6
09:04:06.669 Stack End - Studio
I used a title you can't see because it ruins the fun of the experience.
Just use this code
ConfirmGUI.TextButton.Visible = false
ConfirmGUI.TextButton2.Visible = false
ConfirmGUI.TextLabel.Visible = false
ConfirmGUI.TextTitle.Visible = false
Try using:
script.Parent...Parent:WaitForChild('ConfirmGUI').ScreenGUI, or flip ScreenGUI and ConfurmGUI

How can I save the value of an ID from IE to a variable in VBScript?

I would like to write a program that outputs the email from the website "https://10minutemail.net/" in a message box. Unfortunately, I can't find any code that allows me to store the ID in a variable.
I have tried this already without any results:
Dim email
email = ""
set webbrowser = createobject("internetexplorer.application")
webbrowser.statusbar = false
webbrowser.menubar = false
webbrowser.toolbar = false
webbrowser.visible = false
webbrowser.navigate("10minutemail.net")
email = webbrowser.document.all.item("fe_text")
wscript.echo(email)
The code runs with the Error: [unknown error][1].
[1]: https://i.stack.imgur.com/m1yHF.png
How to fix that?
Vbscript use HTML DOM with this method getElementById to get the particular element in a HTML code source page
So in your case, you can give a try with this code :
Option Explicit
Dim IE,Email_Value
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = False
IE.navigate "https://10minutemail.net/"
Do While (IE.Busy)
WScript.Sleep 100
Loop
Email_Value = IE.document.getElementByID("fe_text").Value
wscript.echo(Email_Value)
IE.Quit()

Can't change Visible property in Label of a VBA UserForm

I've got a Excel form named UserForm1 with a label with this properties:
This label has the property Visible=False. I want to make visible the label when the user click the CommandButton1, for that I wrote the next code:
Private Sub CommandButton1_Click()
Me.Label6.Visible = True
Dim oficina_garsa, file_source, file_solds As String
Dim invoice_year, invoice_month As Integer
oficina_garsa = TextBox3.Value
file_source = TextBox1.Value
file_solds = TextBox2.Value
invoice_year = CInt(ComboBox1.Value)
invoice_month = ComboBox2.ListIndex
Debug.Print oficina_garsa, file_source, file_solds, invoice_year, invoice_month
Call MainProcess(oficina_garsa, file_source, file_solds, invoice_year, invoice_month)
End Sub
But it doesn't work. So I wrote other event code linked to CommandButton2 to testing purpose like this:
Private Sub CommandButton2_Click()
If Me.Label6.Visible = False Then
Me.Label6.Visible = True
Else
Me.Label6.Visible = False
End If
Application.Wait Now + TimeValue("00:00:03")
End Sub
And the last code works fine while the first one doesn't! But in the first code the next code after Me.Label6.Visible = True runs whole without error message.
I've tried replacing 'Me' by 'UserForm1', but the result is the same. Why assigning the Visible property to True works in the CommandButton2 event but doesn't in the CommandButton1 one?
I know this thread is quite old, but as I came across it with the same problem, I thought I'd post the fix.
After setting the visible argument, add a line
Me.Repaint
This will re-render the form and update the visibility of the element. I think the Repaint command is specific to User Forms, so not sure if this will work in other situations where elements are not rendering accurately.

Word Form - using VBA to enable textbox on checkbox click

I have the following VBA code to enable a textbox everytime a checkbox is clicked.
Private Sub CheckName1_Click()
If CheckName1.Value = True Then
TextName1.Enabled = False
TextName1.SpecialEffect = fmSpecialEffectFlat
Else
TextName1.Enabled = True
TextName1.SpecialEffect = fmSpecialEffectSunken
End If
End Sub
The problem is my document will probably have 30 of these by the time I am done (CheckName1, CheckName2, CheckRent1, CheckRent2, etc). I am already having trouble with Word lagging, so I'd like to create a subroutine that will call this sub instead of copy/pasting it again and again.
I haven't spent a lot of time with functions and the like- and even less with VBA. I just know the basics and they always make my head spin. So, this is what I have.
I just don't know how to pass the textbox parameter, or if I even have the checkbox parameter right.
And if this is close, do I still create a call for each checkbox?
Private Sub CheckName1_Click()
Call NA
End Sub
Private Sub NA(checkbox, textbox)
If checkbox.value = True Then
textbox.Enabled = False
textbox.SpecialEffect = fmSpecialEffectFlat
Else
textbox.Enabled = True
textbox.SpecialEffect = fmSpecialEffectSunken
End Sub
Thanks in advance for any help!
Loop on all controls
Based on this example: http://www.ozgrid.com/VBA/control-loop.htm
Dim cCont As Control
For Each cCont In Me.Controls
If TypeName(cCont) = "TextBox" Then
'DO STUFF HERE
End If
Next cCont

VBScript and JScript seem to handle element.click method in a different manner. Why?

guys. Here's another sample script in VBScript. It opens internet explorer, navigates to google, sets up a search field and submits a query.
set ie = CreateObject("InternetExplorer.Application")
ie.navigate("www.google.com")
ie.visible = true
while ie.readystate <> 4
wscript.sleep 100
WEnd
set fields = ie.document.getelementsbyname("q")
set buttons = ie.document.getelementsbyname("btnG")
fields(0).value = "some query"
buttons(0).click
Everything goes o.k.
And here is a script in JScript, that is supposed to do the very same thing:
var ie = new ActiveXObject("InternetExplorer.Application");
ie.visible = true;
ie.navigate("www.google.com");
do {
WScript.Sleep(100);
} while (ie.readystate !== 4);
var input = ie.document.getElementsByName("q");
var button = ie.document.getElementsByName("btnG");
input(0).value = "some query";
button(0).click;
It sets up search field to "some query" correctly, but it doesn't click the button! Literally, nothing happens after input(0).value = "some query"; line.
I'm new to JScript, so I wonder, whether it's me being stupid and ignorant about some specific details, or not?
button(0).click;
Is a reference to a function.
button(0).click();
Would be the function call.
(Also, shouldn't it be square brackets?)