UserForms values and multiple document fields 
Author Message
 UserForms values and multiple document fields

I am trying to get a handle on VBA. I have made good progress but I am
stuck when it comes to syntax sometimes. I need help.

a) I want the user to enter text into a form (frmProjectNo) and have it
update the same field (ProjectNumber) located multiple times throughout the
document.

b)When the user click Save As..., I want to pass a few field values to the
dialog box and concatenate them to make up the suggested filename:
    [ProjectNumber] - [ClientName] - [Date].doc

c) if at all possible, i'd like to use MACROBUTTON field codes (or whatever
else works) to allow the user to doubleclick on any instance of the
ProjectNumber field and get the input form (frmProjectNo) with the
corresponding values filled out (passed from the document to the form, in
case they need to make a correction)

________________you can stop reading here if you know the answer...:-)

So far, in simple code, this is what I have...

a)    on my frmProjectNo OK button:
        Private Sub cmdOK_Click()
            Dim ProjNo As String
            ProjNo = frmProjectNo.lblProjectNo.Text
            ActiveDocument.Fields(4).Result =
frmProjectNo.lblProjectNo.Value         <---type mismatch field to string
            frmProjectNo.Hide
    End Sub

I am getting a type mismatch error, so how can I pass the vallue from the
form to the field?

b)
        With Dialogs(wdDialogFileSaveAs)
            .Name = ActiveDocument.Fields(4).Result & " - " & Format(Date,
"dd MMM yyyy") & ".doc"
            .Show
        End With

is this good enough?

c) ?

Any help would be much appreciated,

regards,

Santy



Sun, 03 Apr 2005 05:20:50 GMT  
 UserForms values and multiple document fields
OK, I tried this:

Private Sub cmdOK_Click()
    Dim BMRange As Range

    Set BMRange = ActiveDocument.Bookmarks("PROJECT_NUMBER").Range
    BMRange.Text = lblProjectNumber
    ActiveDocument.Bookmarks.Add "PROJECT_NUMBER", BMRange

    Set BMRange = ActiveDocument.Bookmarks("CLIENT_NAME").Range
    BMRange.Text = lblClientName
    ActiveDocument.Bookmarks.Add "CLIENT_NAME", BMRange
End Sub

And I repeat a similar statement for about 10 different pieces of
information. is there a better way to code it? with a loop or something?

My Problem now is that on the front page the client name appears in
uppercase, but on subsequent pages it should be TitleCase. How can I change
the REF to display the name in TitleCase and not update itself to the
uppercase version it takes from the bookmark.

Do I use LCase? for all the references? when users print it will update to
UPPERCASE again.

please help.

thanks


Quote:
> I am trying to get a handle on VBA. I have made good progress but I am
> stuck when it comes to syntax sometimes. I need help.

> a) I want the user to enter text into a form (frmProjectNo) and have it
> update the same field (ProjectNumber) located multiple times throughout
the
> document.

> b)When the user click Save As..., I want to pass a few field values to the
> dialog box and concatenate them to make up the suggested filename:
>     [ProjectNumber] - [ClientName] - [Date].doc

> c) if at all possible, i'd like to use MACROBUTTON field codes (or
whatever
> else works) to allow the user to doubleclick on any instance of the
> ProjectNumber field and get the input form (frmProjectNo) with the
> corresponding values filled out (passed from the document to the form, in
> case they need to make a correction)

> ________________you can stop reading here if you know the answer...:-)

> So far, in simple code, this is what I have...

> a)    on my frmProjectNo OK button:
>         Private Sub cmdOK_Click()
>             Dim ProjNo As String
>             ProjNo = frmProjectNo.lblProjectNo.Text
>             ActiveDocument.Fields(4).Result =
> frmProjectNo.lblProjectNo.Value         <---type mismatch field to string
>             frmProjectNo.Hide
>     End Sub

> I am getting a type mismatch error, so how can I pass the vallue from the
> form to the field?

> b)
>         With Dialogs(wdDialogFileSaveAs)
>             .Name = ActiveDocument.Fields(4).Result & " - " & Format(Date,
> "dd MMM yyyy") & ".doc"
>             .Show
>         End With

> is this good enough?

> c) ?

> Any help would be much appreciated,

> regards,

> Santy



Mon, 04 Apr 2005 23:43:02 GMT  
 UserForms values and multiple document fields
Hi Santiago,

Quote:
> Private Sub cmdOK_Click()
>     Dim BMRange As Range

>     Set BMRange = ActiveDocument.Bookmarks("PROJECT_NUMBER").Range
>     BMRange.Text = lblProjectNumber
>     ActiveDocument.Bookmarks.Add "PROJECT_NUMBER", BMRange

>     Set BMRange = ActiveDocument.Bookmarks("CLIENT_NAME").Range
>     BMRange.Text = lblClientName
>     ActiveDocument.Bookmarks.Add "CLIENT_NAME", BMRange
> End Sub

> And I repeat a similar statement for about 10 different pieces of
> information. is there a better way to code it? with a loop or something?

If the controls in your form have the exact same name as the bookmarks in the document, you could do it the other way around, loop through the bookmarks and write the text for each bookmark from the value of the control.
At the Ok button of the userform, try some code like:

--------------------------------------------------------------------
    Dim oBookmark as Bookmark
    Dim oRange as Range
    Dim sName as String

    For Each oBookmark in ActiveDocument.Bookmarks
      set oRange = oBookmark.Range
      sName = oBookmark.Name
      oRange = Me.Controls(sName).Text
      ActiveDocument.Bookmarks.Add sName, oRange
    Next
--------------------------------------------------------------------

Quote:
> My Problem now is that on the front page the client name appears in
> uppercase, but on subsequent pages it should be TitleCase. How can I change
> the REF to display the name in TitleCase and not update itself to the
> uppercase version it takes from the bookmark.

I assume you show the title on subsequent pages with a REF field? Check the different switches that are available for formatting fields in the Helpfile.

Hope this helps,
regards,
Astrid

So that all can benefit from the discussion, please post all follow-ups to the newsgroup.
Visit the MVP Word FAQ site at http://www.mvps.org/word/



Thu, 07 Apr 2005 21:15:53 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Multiple UserForms in a Word Document

2. UserForms for fields on protected documents

3. ActiveX Document--passing fields values

4. URL Command with parameter fields with multiple values

5. passing multiple values from an HTML page to a single parameter field

6. how to handle Multiple values for one field(may be innocense question but.:-)

7. adodb connection to excel: recordset.fields(i).value=null for fields with numeric value

8. adodb connection to excel: recordset.fields(i).value=null for fields with numeric value

9. adodb connection to excel: recordset.fields(i).value=null for fields with numeric value

10. calling multiple userforms

11. Maintaining Active Document Between Userforms

12. Multiple Userforms

 

 
Powered by phpBB® Forum Software