Need some help with coding

wannabepro

Registered User.
Local time
Today, 07:37
Joined
Jan 25, 2005
Messages
102
Okay here is my code, I had thread open awhile back. In regards of exporting main form and subform to word. Here is the code, I am still having problem with it. I can't seen to take export nothing or if I switch around dbs.close and rs.close, I end up exporting whole subform (meaning all the selected text from all the records to on one word doc. I don't know what I am missing, and it has gone beyond the limits and I have turn my brain upside down, but still no answer :( It has to be something with coding. Because, I know my subform is working fine, if I print out a report on access. Help me out plz.

TIA

Code:
Private Sub Command4_Click()

'Declare the follwing
Dim dbs As Database
Dim objDocs As Object
Dim objWord As Word.Application
Dim prps As Object
Dim rst As Recordset
Dim blnSaveNameFail As Boolean
Dim BorrowerID As String
Dim InformationID As Long
Dim intcount As Integer


       'Set word as an application and make it invisible
         Set objWord = CreateObject("Word.Application")
         objWord.Visible = True 'True is visible
    
  
       'path and name of the template your are using.
         objWord.Documents.Add ("C:\Temp\termsheet3.dot")
  
                 
        'This is for the bookmark that you created in the template
         objWord.ActiveDocument.Bookmarks("bmCusadd").Select
         
       'This is the field in access that containts the data that has to be entered at the
       'bookmark
         objWord.Selection.Text = Forms![menu]![txtCusDetails]
         
         objWord.ActiveDocument.Bookmarks("bmcoadd").Select
          objWord.Selection.Text = Forms![menu]![txtcoadd]
          
        objWord.ActiveDocument.Bookmarks("bmcoadd1").Select
          objWord.Selection.Text = Forms![menu]![txtcoadd1]
          
           objWord.ActiveDocument.Bookmarks("bmborrower").Select
          objWord.Selection.Text = Forms![menu]![txtborrower1]

          objWord.ActiveDocument.Bookmarks("bmborrower2").Select
          objWord.Selection.Text = Forms![menu]![txtborrower2]
          
          objWord.ActiveDocument.Bookmarks("bmGuarnator").Select
          objWord.Selection.Text = Forms![menu]![txtGuarnator]
            
            objWord.ActiveDocument.Variables("bmmoney").Value _
         = Forms![menu]![txtloanamt]
          
              objWord.ActiveDocument.Variables("bmpercent").Value _
         = Forms![menu]![txtperc]
           
           objWord.ActiveDocument.Variables("bmloanpur").Value _
         = Forms![menu]![txtloanpur1]
                     
           objWord.ActiveDocument.Variables("bmloanpurpose").Value _
         = Forms![menu]![txtloanpurpose]
         
          objWord.ActiveDocument.Bookmarks("bmterms").Select
          objWord.Selection.Text = Forms![menu]![txtterm]
          
          objWord.ActiveDocument.Bookmarks("bmAmortTerm").Select
          objWord.Selection.Text = Forms![menu]![txtamortterm]
          
          objWord.ActiveDocument.Bookmarks("bminterestyear").Select
          objWord.Selection.Text = Forms![menu]![txtinterestyear]
          
          objWord.ActiveDocument.Bookmarks("bminterest1").Select
          objWord.Selection.Text = Forms![menu]![txtinterestrate1]
                    
          objWord.ActiveDocument.Bookmarks("bmsecurity1").Select
          objWord.Selection.Text = Forms![menu]![txtsecurity1]
                    
            objWord.ActiveDocument.Variables("bmsecurity2").Value _
         = Forms![menu]![txtsecurity2]
          
          objWord.ActiveDocument.Bookmarks("bmsecurity3").Select
          objWord.Selection.Text = Forms![menu]![txtsecurity3]
                  
           objWord.ActiveDocument.Variables("bmsecurity4").Value _
         = Forms![menu]![txtsecurity4]
                    
            objWord.ActiveDocument.Variables("bmworkfee").Value _
         = Forms![menu]![txtworkfee]
                 
           objWord.ActiveDocument.Variables("bminsurance2").Value _
         = Forms![menu]![txtinurance2]
         
          objWord.ActiveDocument.Bookmarks("bmperdebt").Select
          objWord.Selection.Text = Forms![menu]![txtperdebt]
          
            objWord.ActiveDocument.Variables("bminsurance1").Value _
         = Forms![menu]![txtinsurance1]
          
          objWord.ActiveDocument.Bookmarks("bmaudited").Select
          objWord.Selection.Text = Forms![menu]![txtaudited]
                    
          objWord.ActiveDocument.Bookmarks("bmborrower1").Select
          objWord.Selection.Text = Forms![menu]![txtborrower1]
          
          objWord.ActiveDocument.Bookmarks("bmGuarantor1").Select
          objWord.Selection.Text = Forms![menu]![txtguarantor1]
          
          objWord.ActiveDocument.Bookmarks("bmBorrower3").Select
          objWord.Selection.Text = Forms![menu]![txtBorrower3]
          
          objWord.ActiveDocument.Variables("bmaccepteddate").Value _
         = Forms![menu]![txtaccepteddate]
          
          objWord.ActiveDocument.Bookmarks("bmGuarantor3").Select
          objWord.Selection.Text = Forms![menu]![txtGuarantor3]
          
          objWord.ActiveDocument.Bookmarks("bmdearmsmr").Select
          objWord.Selection.Text = Forms![menu]![txtbmdearmrms]

DoCmd.SetWarnings False
DoCmd.OpenQuery "qmakInvoice"

  
  intcount = DCount("*", "tmakInvoice")
Debug.Print "Number of Detail item: " & intcount

If intcount < 1 Then
MsgBox "No detail items for invoice; canceling"
Exit Sub
End If
Set dbs = CurrentDb
  Set rst = dbs.OpenRecordset("tmakInvoice", dbOpenDynaset)
  With rst
  .MoveFirst
  Do While Not .EOF
  BorrowerID = Nz(![Borrower ID])
  Debug.Print "[Borrower ID]:" & BorrowerID
      With objWord.Selection
  .TypeText Text:=BorrowerID
  .MoveDown Unit:=wdLine, Count:=2
  '.MoveRight Unit:=wdCell
   End With
  .MoveNext
  Loop
  .Close
  End With
 
 
 With objWord.Selection
  .GoTo what:=wdGoToTable, which:=wdGoToFirst, Count:=3, Name:=""
 .MoveDown Unit:=wdLine, Count:=1
  End With
  dbs.Close
            objWord.ActiveDocument.Fields.Update
         
'Word (or the document that you created with the template, will now open)
    objWord.Visible = True


Set objWord = Nothing
'rst.Close
Exit Sub
'End With

End Sub
 
Pat, thanx, I did try that before, but for some reason it didn't work for me. And now all of a sudden it did. Proly, I was doing something wrong before. But, I really appreciate your help :)
 

Users who are viewing this thread

Back
Top Bottom