Creating a variable

P

Patrick C. Simonds

This is what I need to do:

If TextBox1 on UserForm1 is blank when the UserForm is unloaded, I want to
create a public variable called "incomplete" (would also want that
variable deleted if it already existed and TextBox1 were not blank when the
UserForm where unloaded). Then when I open UserForm4 if the variable
"incomplete" exists, I want the BackColor of CommandButton1 to be red.
 
P

Patrick C. Simonds

I think I may have figured this out. I will be back if things do not work
out. Thanks
 
P

Patrick C. Simonds

My problem now is that having created the code below, if I access the
UserForm again I get an error because the variable all ready exists.



Private Sub CommandButton1_Click()

Unload UserForm1

Title = (Me.OptionButton1 Or Me.OptionButton2 Or Me.OptionButton3 Or
Me.OptionButton4)

If Title = False Then

ActiveDocument.Variables.Add Name:="Incomplete", Value:="True"

End If

End Sub
 
P

Patrick C. Simonds

This did the trick. If anyone has a better way though I am always ready to
learn.


Private Sub CommandButton1_Click()

Unload UserForm1

On Error GoTo Continue

ActiveDocument.Variables.Add Name:="Incomplete"

Continue:

Title = (Me.OptionButton1 Or Me.OptionButton2 Or Me.OptionButton3 Or
Me.OptionButton4)

If Title = False Then

ActiveDocument.Variables("Incomplete").Value = True

End If

End Sub
 
D

Doug Robbins - Word MVP

You do not have to specifically "Add" a document variable. Assigning a
value to it with

[document object].Variables("Varname").Value =

will cause it to be created with the assigned value if it does not exist, or
change the value assigned to it if it already exists.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
P

Patrick C. Simonds

Can anyone explain to me why the code below does not change the BackColor of
CommandButton1?

I added the "MsgBox ActiveDocument.Variables("Personal").Value" code just
so I could make sure the variable value was in fact "test".



Private Sub UserForm_Initialize()

MsgBox ActiveDocument.Variables("Personal").Value

If ActiveDocument.Variables("Personal").Value = "test" Then
CommandButton1.BackColor = &H8000000F
End If

End Sub







Doug Robbins - Word MVP said:
You do not have to specifically "Add" a document variable. Assigning a
value to it with

[document object].Variables("Varname").Value =

will cause it to be created with the assigned value if it does not exist,
or change the value assigned to it if it already exists.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Patrick C. Simonds said:
This did the trick. If anyone has a better way though I am always ready
to learn.


Private Sub CommandButton1_Click()

Unload UserForm1

On Error GoTo Continue

ActiveDocument.Variables.Add Name:="Incomplete"

Continue:

Title = (Me.OptionButton1 Or Me.OptionButton2 Or Me.OptionButton3 Or
Me.OptionButton4)

If Title = False Then

ActiveDocument.Variables("Incomplete").Value = True

End If

End Sub
 
D

Doug Robbins - Word MVP

I am not sure what, if any color is represented by &H8000000F

However, the following works:

If ActiveDocument.Variables("Personal").Value = "test" Then
CommandButton1.BackColor = wdColorRed
Else
CommandButton1.BackColor = wdColorGreen
End If


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Patrick C. Simonds said:
Can anyone explain to me why the code below does not change the BackColor
of CommandButton1?

I added the "MsgBox ActiveDocument.Variables("Personal").Value" code just
so I could make sure the variable value was in fact "test".



Private Sub UserForm_Initialize()

MsgBox ActiveDocument.Variables("Personal").Value

If ActiveDocument.Variables("Personal").Value = "test" Then
CommandButton1.BackColor = &H8000000F
End If

End Sub







Doug Robbins - Word MVP said:
You do not have to specifically "Add" a document variable. Assigning a
value to it with

[document object].Variables("Varname").Value =

will cause it to be created with the assigned value if it does not exist,
or change the value assigned to it if it already exists.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Patrick C. Simonds said:
This did the trick. If anyone has a better way though I am always ready
to learn.


Private Sub CommandButton1_Click()

Unload UserForm1

On Error GoTo Continue

ActiveDocument.Variables.Add Name:="Incomplete"

Continue:

Title = (Me.OptionButton1 Or Me.OptionButton2 Or Me.OptionButton3 Or
Me.OptionButton4)

If Title = False Then

ActiveDocument.Variables("Incomplete").Value = True

End If

End Sub


My problem now is that having created the code below, if I access the
UserForm again I get an error because the variable all ready exists.



Private Sub CommandButton1_Click()

Unload UserForm1

Title = (Me.OptionButton1 Or Me.OptionButton2 Or Me.OptionButton3 Or
Me.OptionButton4)

If Title = False Then

ActiveDocument.Variables.Add Name:="Incomplete", Value:="True"

End If

End Sub





I think I may have figured this out. I will be back if things do not
work out. Thanks

This is what I need to do:

If TextBox1 on UserForm1 is blank when the UserForm is unloaded, I
want to create a public variable called "incomplete" (would also
want that variable deleted if it already existed and TextBox1 were
not blank when the UserForm where unloaded). Then when I open
UserForm4 if the variable "incomplete" exists, I want the BackColor
of CommandButton1 to be red.
 
T

Tony Jollans

&H8000000F is the Windows system colour for 3-D Face. I'm not sure off the
top of my head exactly which elements this would apply to but command button
back colour wouldn't surprise me - and that would explain why setting it to
that value had no effect.

--
Enjoy,

Tony Jollans
Microsoft Word MVP

Doug Robbins - Word MVP said:
I am not sure what, if any color is represented by &H8000000F

However, the following works:

If ActiveDocument.Variables("Personal").Value = "test" Then
CommandButton1.BackColor = wdColorRed
Else
CommandButton1.BackColor = wdColorGreen
End If


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Patrick C. Simonds said:
Can anyone explain to me why the code below does not change the BackColor
of CommandButton1?

I added the "MsgBox ActiveDocument.Variables("Personal").Value" code
just so I could make sure the variable value was in fact "test".



Private Sub UserForm_Initialize()

MsgBox ActiveDocument.Variables("Personal").Value

If ActiveDocument.Variables("Personal").Value = "test" Then
CommandButton1.BackColor = &H8000000F
End If

End Sub







Doug Robbins - Word MVP said:
You do not have to specifically "Add" a document variable. Assigning a
value to it with

[document object].Variables("Varname").Value =

will cause it to be created with the assigned value if it does not
exist, or change the value assigned to it if it already exists.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

This did the trick. If anyone has a better way though I am always ready
to learn.


Private Sub CommandButton1_Click()

Unload UserForm1

On Error GoTo Continue

ActiveDocument.Variables.Add Name:="Incomplete"

Continue:

Title = (Me.OptionButton1 Or Me.OptionButton2 Or Me.OptionButton3 Or
Me.OptionButton4)

If Title = False Then

ActiveDocument.Variables("Incomplete").Value = True

End If

End Sub


My problem now is that having created the code below, if I access the
UserForm again I get an error because the variable all ready exists.



Private Sub CommandButton1_Click()

Unload UserForm1

Title = (Me.OptionButton1 Or Me.OptionButton2 Or Me.OptionButton3 Or
Me.OptionButton4)

If Title = False Then

ActiveDocument.Variables.Add Name:="Incomplete", Value:="True"

End If

End Sub





I think I may have figured this out. I will be back if things do not
work out. Thanks

This is what I need to do:

If TextBox1 on UserForm1 is blank when the UserForm is unloaded, I
want to create a public variable called "incomplete" (would also
want that variable deleted if it already existed and TextBox1 were
not blank when the UserForm where unloaded). Then when I open
UserForm4 if the variable "incomplete" exists, I want the BackColor
of CommandButton1 to be red.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top