I have a macro
Sub Save2()
Dim vRefferingPhysician, vDate As String
If vRefferingPhysician = "Swain"
Then
Save
Else
SaveR
End If
End Sub
when I run the code it will always run the saveR macro, even if the field
is swain am I asking the right if question?
Thanks

Re: If Staement question by Ed

Ed
Thu Apr 07 09:48:50 CDT 2005

How are you getting the field value of "Swain" into your variable
vRefferingPhysician?
(Note1: If you want vRefferingPhysician to be a String variable, then you
must assign it -
Dim vRefferingPhysician As String, vDate As String
Otherwise it is by default a "variable", which could possibly be interpreted
as an incorrect value.)
(Note2: If you are trying to pass vRefferingPhysician in from another
procedure or function, or pick it up from a field code, is it possible you
have it spelled correctly in the other place (vReferringPhysician), and the
typo is causing you difficulties?)
Ed

"coconutt" <coconutt@discussions.microsoft.com> wrote in message
news:4D88B446-74FA-40CC-9B3C-28D7FDECDB69@microsoft.com...
> I have a macro
> Sub Save2()
> Dim vRefferingPhysician, vDate As String
> If vRefferingPhysician = "Swain"
> Then
> Save
> Else
> SaveR
> End If
> End Sub
> when I run the code it will always run the saveR macro, even if the field
> is swain am I asking the right if question?
> Thanks



Re: If Staement question by Jay

Jay
Thu Apr 07 10:05:10 CDT 2005

coconutt wrote:
> I have a macro
> Sub Save2()
> Dim vRefferingPhysician, vDate As String
> If vRefferingPhysician = "Swain"
> Then
> Save
> Else
> SaveR
> End If
> End Sub
> when I run the code it will always run the saveR macro, even if the
> field is swain am I asking the right if question?
> Thanks

Hi coconutt,

The question is OK (almost) but you've neglected to give the variable
vRefferingPhysician any value, so the comparison can never be true.

What is "the field"? If it's a text form field in a protected form, use the
name assigned to it in the field's Properties dialog to do something like
this before the If statement:

vRefferingPhysician = _
ActiveDocument.FormFields("RefferingPhysician").Result

The "almost" part is that the comparison is case-sensitive, so you probably
should do this instead:

If LCase(vRefferingPhysician) = "swain"

One more bit, not critical but a bad habit: By omitting the "As" clause for
vRefferingPhysician in your Dim statement, you've implicitly declared it as
Variant data type, not String. Each variable in a Dim statement needs its
own As clause. It should be

Dim vRefferingPhysician As String, vDate As String

(And what is vDate? you don't use it.)

Lastly, my sensibility is offended by the misspelling of 'referring'. ;-)

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org



Re: If Staement question by coconutt

coconutt
Thu Apr 07 10:17:10 CDT 2005

here are some snippets

Dim vRefferingPhysician, vPatientName, vCurrentTreatment As String
'setting variables to the form
vRefferingPhysician = frmInfoForm.txtRefferingPhysician.Text
'Populating the word document bookmarks
ActiveDocument.FormFields("bkRefPhysician").Result = vRefferingPhysician

all this works fine when i click ok on my info form
I doublechecked the spelling, and stepped through the code and it holds the
info.
should i do something else?






"Ed" wrote:

> How are you getting the field value of "Swain" into your variable
> vRefferingPhysician?
> (Note1: If you want vRefferingPhysician to be a String variable, then you
> must assign it -
> Dim vRefferingPhysician As String, vDate As String
> Otherwise it is by default a "variable", which could possibly be interpreted
> as an incorrect value.)
> (Note2: If you are trying to pass vRefferingPhysician in from another
> procedure or function, or pick it up from a field code, is it possible you
> have it spelled correctly in the other place (vReferringPhysician), and the
> typo is causing you difficulties?)
> Ed
>
> "coconutt" <coconutt@discussions.microsoft.com> wrote in message
> news:4D88B446-74FA-40CC-9B3C-28D7FDECDB69@microsoft.com...
> > I have a macro
> > Sub Save2()
> > Dim vRefferingPhysician, vDate As String
> > If vRefferingPhysician = "Swain"
> > Then
> > Save
> > Else
> > SaveR
> > End If
> > End Sub
> > when I run the code it will always run the saveR macro, even if the field
> > is swain am I asking the right if question?
> > Thanks
>
>
>

Re: If Staement question by Ed

Ed
Thu Apr 07 11:27:51 CDT 2005

First, put the As String declaration after each of your string variables.
Putting them altogether on one line with As String at the end does NOT make
them all string variables (I did this, too, in my beginning days (not too
long ago!), and ran into odd problems.)
Dim vRefferingPhysician As String, vDate As String

Next, load a text string into the variable
vRefferingPhysician =
ActiveDocument.Bookmarks("bkRefPhysician").Range.Text
(As a test, I would do something like
MsgBox vRefferingPhysician
to make sure you have the expected text in the string.)

Ed

"coconutt" <coconutt@discussions.microsoft.com> wrote in message
news:379A2E78-1E26-44B7-8B29-CE4FD5E14B78@microsoft.com...
> here are some snippets
>
> Dim vRefferingPhysician, vPatientName, vCurrentTreatment As String
> 'setting variables to the form
> vRefferingPhysician = frmInfoForm.txtRefferingPhysician.Text
> 'Populating the word document bookmarks
> ActiveDocument.FormFields("bkRefPhysician").Result = vRefferingPhysician
>
> all this works fine when i click ok on my info form
> I doublechecked the spelling, and stepped through the code and it holds
the
> info.
> should i do something else?
>
>
>
>
>
>
> "Ed" wrote:
>
> > How are you getting the field value of "Swain" into your variable
> > vRefferingPhysician?
> > (Note1: If you want vRefferingPhysician to be a String variable, then
you
> > must assign it -
> > Dim vRefferingPhysician As String, vDate As String
> > Otherwise it is by default a "variable", which could possibly be
interpreted
> > as an incorrect value.)
> > (Note2: If you are trying to pass vRefferingPhysician in from another
> > procedure or function, or pick it up from a field code, is it possible
you
> > have it spelled correctly in the other place (vReferringPhysician), and
the
> > typo is causing you difficulties?)
> > Ed
> >
> > "coconutt" <coconutt@discussions.microsoft.com> wrote in message
> > news:4D88B446-74FA-40CC-9B3C-28D7FDECDB69@microsoft.com...
> > > I have a macro
> > > Sub Save2()
> > > Dim vRefferingPhysician, vDate As String
> > > If vRefferingPhysician = "Swain"
> > > Then
> > > Save
> > > Else
> > > SaveR
> > > End If
> > > End Sub
> > > when I run the code it will always run the saveR macro, even if the
field
> > > is swain am I asking the right if question?
> > > Thanks
> >
> >
> >