Hi

I'm sure there is a simple answer to this but I can't find it.

I have a word document that asks a question in the Private Sub
Document_open() and puts it in to a Variable. The same sub creates a Submit
Button that calls Public Sub cmdSubmit_Click(). The problem is the cmdSubmit
coding does not get the value given to the variable in the Document_open.

I have tried declaring the variables Public and Static and all that kind of
stuff (I think) but without success.

Thanks in advance

Gaz

Re: Word variables - public? static? by Doug

Doug
Mon Aug 01 11:02:59 CDT 2005

Show us the code.

--
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
"Gaz uk" <Gazuk@discussions.microsoft.com> wrote in message
news:24F859E2-BCD1-4C16-9E79-BD31554997D3@microsoft.com...
> Hi
>
> I'm sure there is a simple answer to this but I can't find it.
>
> I have a word document that asks a question in the Private Sub
> Document_open() and puts it in to a Variable. The same sub creates a
> Submit
> Button that calls Public Sub cmdSubmit_Click(). The problem is the
> cmdSubmit
> coding does not get the value given to the variable in the Document_open.
>
> I have tried declaring the variables Public and Static and all that kind
> of
> stuff (I think) but without success.
>
> Thanks in advance
>
> Gaz



Re: Word variables - public? static? by Gazuk

Gazuk
Wed Aug 03 12:08:03 CDT 2005

This isn't the exact code, but you get the idea......

Public vName

Private Sub CommandButton1_Click()
x = MsgBox(vName)
End Sub

Private Sub Document_Open()
vName = InputBox("Input Name")

Set vCmdSubmit =
Selection.InlineShapes.AddOLEControl(ClassType:="Forms.CommandButton.1")
With vCmdSubmit.OLEFormat.Object
.Name = "CommandButton1"
.Caption = "Submit"
.AutoSize = True

End With
End Sub


Thanks

Gaz

"Doug Robbins" wrote:

> Show us the code.
>
> --
> 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
> "Gaz uk" <Gazuk@discussions.microsoft.com> wrote in message
> news:24F859E2-BCD1-4C16-9E79-BD31554997D3@microsoft.com...
> > Hi
> >
> > I'm sure there is a simple answer to this but I can't find it.
> >
> > I have a word document that asks a question in the Private Sub
> > Document_open() and puts it in to a Variable. The same sub creates a
> > Submit
> > Button that calls Public Sub cmdSubmit_Click(). The problem is the
> > cmdSubmit
> > coding does not get the value given to the variable in the Document_open.
> >
> > I have tried declaring the variables Public and Static and all that kind
> > of
> > stuff (I think) but without success.
> >
> > Thanks in advance
> >
> > Gaz
>
>
>

Re: Word variables - public? static? by Jean-Guy

Jean-Guy
Wed Aug 03 13:58:11 CDT 2005

Gaz uk was telling us:
Gaz uk nous racontait que :

> This isn't the exact code, but you get the idea......
>
> Public vName
>
> Private Sub CommandButton1_Click()
> x = MsgBox(vName)
> End Sub
>
> Private Sub Document_Open()
> vName = InputBox("Input Name")
>
> Set vCmdSubmit =
> Selection.InlineShapes.AddOLEControl(ClassType:="Forms.CommandButton.1")
> With vCmdSubmit.OLEFormat.Object
> .Name = "CommandButton1"
> .Caption = "Submit"
> .AutoSize = True
>
> End With
> End Sub
>

Where is Public vName declared (In which module)?
From your "inexact" code, it looks like it is declared in the userform code
module. It helps those who are trying to help (on their own time) to provide
as much information as possible.

This is fine as long as the variable is not needed by other modules.
In your case, you should declare your public variable in a regular module
(Not in ThisDocument module, which, like the userform module, is a class
module). Class modules do not share public variables with other modules.

So, create a regular module and declare your public variables there.

I know some people frown on public variables... For example, in your case,
there would be a way to pass the variable as a parameter when calling the
userform and avoid the need for a public variable...
But, for simple stuff like this, I do not think that a public variable can
be a problem.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org