I am creating a word document from a command button on an Access form. I have created the basic report and belive that I have populated an array with a single record (1 row by X columns) I want to create a concatenated string of the values in the array, to be output onto the word document. I'm stuck!
My code is as follows:
Sub PrintReportWithWord(frmDay As Form_frmDay)
On Error GoTo PrintReportWithWord_Err
Dim objWord As New Word.Application
Dim strSQL As String
Dim rst As Recordset
Dim frm1 As Form
Dim OpsList As String
Dim DrlgList As String
Dim IntCtr As Integer
'Launch Word and load the Report Template
Set objWord = New Word.Application
objWord.Documents.Add _
Application.CurrentProject.Path & "\MgrsRpt.dot"
objWord.Visible = True
'Add header information using predefined bookmarks
With objWord.ActiveDocument.Bookmarks
.Item("WellName"
.Range.Text = frmDay.WellName
.Item("County"
.Range.Text = frmDay.County
.Item("WellNo"
.Range.Text = frmDay.WellNo
.Item("State"
.Range.Text = frmDay.State
.Item("RptDate"
.Range.Text = Forms!frmDay!Status.Form!Date
.Item("OART"
.Range.Text = Forms!frmDay!Status.Form!OART
.Item("CumCost"
.Range.Text = FormatCurrency(Forms!frmDay!Status.Form!txtCasingIntanCum, 2)
.Item("DailyCost"
.Range.Text = FormatCurrency(Forms!frmDay!Status.Form!txtCasingIntanTotal, 2)
.Item("DOW"
.Range.Text = "Day " & Forms!frmDay!Status.Form!DaysOnWell
.Item("MD"
.Range.Text = Forms!frmDay!Status.Form!DepthAt & "'"
.Item("Ftg"
.Range.Text = Forms!frmDay!Status.Form![DrilledIn24] & "'"
Call GetOperations
End With
PrintReportWithWord_Err:
'If a field on the form is empty, remove the bookmark text, and continue.
If Err.Number = 94 Then
objWord.Selection.Text = ""
Resume Next
End If
End Sub
'**********************************************************************************
Public Sub GetOperations()
'Use an array to process data in a recordset
Dim dbs As Database
Dim rst As Recordset
Dim varData As Variant
Dim intCount As Integer
Dim intI As Integer
Dim strSQL As String
Dim strOPS As String
Set dbs = CurrentDb()
strSQL = "SELECT * FROM Operations where Operations.DayID =" & Forms!frmDay!Status.Form.DayID
Set rst = dbs.OpenRecordset(strSQL, dbOpenSnapshot)
varData = rst.GetRows()
intCount = UBound(varData, 2) + 1
'MsgBox "The number of rows is " & intCount
For intI = intCount - 1 To 0 Step -1
strOPS = "strOPS" + (varData(0, intI), vardata(1, inti))
Next intI
rst.Close
Set dbs = Nothing
End Sub
Any help would be appreciated
Thanks
BusMgr
My code is as follows:
Sub PrintReportWithWord(frmDay As Form_frmDay)
On Error GoTo PrintReportWithWord_Err
Dim objWord As New Word.Application
Dim strSQL As String
Dim rst As Recordset
Dim frm1 As Form
Dim OpsList As String
Dim DrlgList As String
Dim IntCtr As Integer
'Launch Word and load the Report Template
Set objWord = New Word.Application
objWord.Documents.Add _
Application.CurrentProject.Path & "\MgrsRpt.dot"
objWord.Visible = True
'Add header information using predefined bookmarks
With objWord.ActiveDocument.Bookmarks
.Item("WellName"
.Item("County"
.Item("WellNo"
.Item("State"
.Item("RptDate"
.Item("OART"
.Item("CumCost"
.Item("DailyCost"
.Item("DOW"
.Item("MD"
.Item("Ftg"
Call GetOperations
End With
PrintReportWithWord_Err:
'If a field on the form is empty, remove the bookmark text, and continue.
If Err.Number = 94 Then
objWord.Selection.Text = ""
Resume Next
End If
End Sub
'**********************************************************************************
Public Sub GetOperations()
'Use an array to process data in a recordset
Dim dbs As Database
Dim rst As Recordset
Dim varData As Variant
Dim intCount As Integer
Dim intI As Integer
Dim strSQL As String
Dim strOPS As String
Set dbs = CurrentDb()
strSQL = "SELECT * FROM Operations where Operations.DayID =" & Forms!frmDay!Status.Form.DayID
Set rst = dbs.OpenRecordset(strSQL, dbOpenSnapshot)
varData = rst.GetRows()
intCount = UBound(varData, 2) + 1
'MsgBox "The number of rows is " & intCount
For intI = intCount - 1 To 0 Step -1
strOPS = "strOPS" + (varData(0, intI), vardata(1, inti))
Next intI
rst.Close
Set dbs = Nothing
End Sub
Any help would be appreciated
Thanks
BusMgr