Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Concatenated string from array

Status
Not open for further replies.

BusMgr

IS-IT--Management
Aug 21, 2001
138
US
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
 
varData = rst.GetRows(100000) 'Need a big number here to get everything. Then once you have it do the following to get all of the columns in the row:

For intI = 0 To UBound(varData, 1) '<= The column count
strOps = strOps & vardata(intI, 0) '<= Only 1 row
Next intI

In VBA, arrays are zero based. GetRows returns a 2 dimensional array but you said you only have 1 row so it will be the zeroth row that you process. Hope this helps and good luck!


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top