Results 1 to 5 of 5
  1. #1
    4 Star Lounger
    Join Date
    Aug 2001
    Location
    London, UK
    Posts
    516
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Formula in word? (Office 2000)

    Is there anyway of putting a formula in a document to calculate the number of rows in a table???

  2. #2
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Formula in word? (Office 2000)

    Princess, you're doing real work <img src=/S/question.gif border=0 alt=question width=15 height=15> You have to give up one cell in your table, preferable in the first row. In this cell, insert the formula =count(below) with the Table>Formula. If you have to use a different row, then add an offset to that formula. Now, select the entire cell and give it a bookmark (Insert>Bookmark), say Tbl2Count. Finally, go to where you want this number in the text and use the Table>Formula menu to enter =Tbl2Count or whatever name you used. Also remember, if you don't want to see the number in the table, you can just make the text white. HTH --Sam AKA <img src=/S/gramps.gif border=0 alt=gramps width=20 height=20>
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  3. #3
    4 Star Lounger
    Join Date
    Aug 2001
    Location
    London, UK
    Posts
    516
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Formula in word? (Office 2000)

    Ofcourse Im doing REAL work <img src=/S/gramps.gif border=0 alt=gramps width=20 height=20> Im on my work placement.
    Anywayz I tried what you told me to do and it displays "!Unexpected End of Formula", What I didn't tell you was that this document is a mail merged document and the main document type is a CATALOG.
    Any suggestions??

  4. #4
    Star Lounger
    Join Date
    Mar 2001
    Posts
    73
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Formula in word? (Office 2000)


  5. #5
    4 Star Lounger
    Join Date
    Aug 2001
    Location
    London, UK
    Posts
    516
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Formula in word? (Office 2000)

    <pre>Sub GetTotalDocumentRowCount()
    ' Loop through tables in body of active document.
    For Each tblTable In ActiveDocument.Tables
    ' Obtain count of rows for each table and combine.
    iCount = iCount + tblTable.Rows.Count
    Next
    MsgBox iCount
    End Sub
    </pre>

    The above module is helpful coz it returns the value but How do I print this on the same page? Im creating this from Access using the following module:
    <pre>Option Compare Database
    Const CSTR_SAVEPATH As String = "S:SRI_WORK_AREADOCUME~1"
    Const CSTR_DOCSPATH As String = "C:TradarDevelopment"
    Sub CitcoFax()
    Dim strFileName As String, strMsg As String, vResult As Variant
    Dim strFilenamePart As String, appWord As Object
    Dim db As DAO.Database
    Dim rst As DAO.Recordset
    Dim rstRecipients As DAO.Recordset
    Dim strFund As String
    Dim rstCitco As DAO.Recordset
    Dim strTDate As Date
    Dim objWord As Object, strMessage As String, strMsgTitle As String
    strFund = "Soros"
    'Turn System warnings off
    DoCmd.SetWarnings False
    'Delete contents of the table
    DoCmd.RunSQL "DELETE [tblCitco].* FROM [tblCitco] WITH OWNERACCESS OPTION;", 0
    'Run Append query to add SFM records to the table
    DoCmd.OpenQuery "AppToCitco", acNormal, acEdit
    'Turn System warnings on.
    DoCmd.SetWarnings True
    Set db = CurrentDb
    Set rst = db.OpenRecordset("tblCitco")
    If rst.BOF And rst.EOF Then
    vResult = MsgBox("There are no records. Would you like to send a fax?", _
    vbQuestion + vbYesNo + vbMsgBoxSetForeground)
    If vResult = vbYes Then
    'set value to merge
    Set rstRecipients = db.OpenRecordset("tblRecipient", dbOpenDynaset)
    With rstRecipients
    .MoveFirst
    .FindFirst "[Fund] = '" & strFund & "'"
    .Edit
    !Merge = True
    .Update
    End With
    Set rstRecipients = Nothing
    'Output data to spreadsheet
    strFileName = CSTR_DOCSPATH & "FAXSOURCE.xls"
    DoCmd.OutputTo acOutputQuery, "qryRecipient", acFormatXLS, strFileName, False
    'Open fax cover
    Set objWord = GetObject(CSTR_DOCSPATH & "Fax.doc", "Word.Document")
    'Make word visible
    With objWord
    .Application.Visible = True
    'Execute the mail merge
    With .MailMerge
    .destination = wdSendToNewDocument
    .Execute
    End With
    Set appWord = .Application
    End With
    appWord.DisplayAlerts = wdAlertsNone
    objWord.Close
    appWord.DisplayAlerts = wdAlertsAll
    'Update tblRecipient
    DoCmd.OpenQuery "UpdRecipients(Merge)", acNormal, acEdit
    Else
    End If
    Else
    strFileName = CSTR_DOCSPATH & "BCPSOURCE.xls"
    DoCmd.OutputTo acOutputQuery, "Citco", acFormatXLS, strFileName, False
    Set objWord = GetObject(CSTR_DOCSPATH & "Citco.doc", "Word.Document")
    'set value to Date
    Set rstCitco = db.OpenRecordset("tblCitco", dbOpenDynaset)
    With rstCitco
    TDate = rst![ td ]
    End With
    'Make word visible.
    With objWord
    .Application.Visible = True
    'Execute the mail merge.
    With .MailMerge
    .destination = wdSendToNewDocument
    .Execute
    End With
    Set appWord = .Application
    End With
    appWord.DisplayAlerts = wdAlertsNone
    objWord.Close
    appWord.DisplayAlerts = wdAlertsAll
    strFileName = CSTR_SAVEPATH & "CitcoFax" & Format(TDate, "DDMMYY") & ".doc"
    strMsgTitle = "Buttonwood Trade Administration System"
    vResult = Dir(strFileName)
    If vResult <> "" Then
    strMessage = "File " & strFileName & " already exists," & _
    vbCrLf & vbCrLf & "Would you like to overwrite that file?" & _
    vbCrLf & vbCrLf & "Click Yes to overwrite the file" & _
    vbCrLf & vbCrLf & "Click No to save the file with another name" & _
    vbCrLf & vbCrLf & "Click Cancel to return to the document without saving."
    vResult = MsgBox(strMessage, vbQuestion + vbYesNoCancel + vbMsgBoxSetForeground, strMsgTitle)
    Select Case vResult
    Case Is = vbYes
    With appWord
    .DisplayAlerts = False
    .ActiveDocument.SaveAs filename:=strFileName, FileFormat:=wdFormatDocument
    MsgBox "Document has been saved.", vbInformation + vbMsgBoxSetForeground, strMsgTitle
    .DisplayAlerts = True
    End With
    Case Is = vbNo
    strFileName = InputBox("File " & strFileName & " already exists," _
    & Chr(10) & "Please enter another filename not including " _
    & Chr(34) & ".doc" & Chr(34) & ": ") & ".doc"
    If strFileName = ".doc" Then
    MsgBox "You've clicked on cancel," _
    & " the document has not been saved.", vbInformation + vbMsgBoxSetForeground, strMsgTitle
    Else
    appWord.ActiveDocument.SaveAs _
    filename:=CSTR_SAVEPATH & strFileName, FileFormat:=wdFormatDocument
    MsgBox "Document has been saved.", vbInformation + vbMsgBoxSetForeground, strMsgTitle
    End If
    Case Else
    MsgBox "You've chosen not to save the document.", vbInformation + vbMsgBoxSetForeground, strMsgTitle
    End Select
    Else
    With appWord
    .DisplayAlerts = False
    .ActiveDocument.SaveAs filename:=strFileName, _
    FileFormat:=wdFormatDocument
    .DisplayAlerts = True
    MsgBox "Document has been saved.", vbInformation + vbMsgBoxSetForeground, strMsgTitle
    End With
    End If
    AppActivate "Microsoft Word" ' Activate Microsoft Word.
    End If
    cleanup:
    On Error Resume Next
    Set objWord = Nothing
    Set appWord = Nothing
    Set rst = Nothing
    Set db = Nothing
    End Sub
    </pre>


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •