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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing trough recordset to excel

Status
Not open for further replies.

lode

Programmer
Nov 8, 2001
208
BE
Hi,
Does anybody know how i can passing trough a recordset from VB to an excel application ??

Thanks

Lode.
 
The only way that I know how to do this is to populate an array with the recordset and then set the worksheet = the array. I have used this and it works very well.

Nate
 
Hi Lode

This is a lazy way of answering you question. I have just copied some code from a procedure of mine.Hope I understand what you want and hope this may help.

You will have to read through the other stuff which is not relevant to you.

---------
Dim objE As Object
Dim objW As Object
Dim blnR As Boolean
Dim Sfile As String

On Error Resume Next

ComFile1.ShowOpen

Sfile = ComFile1.FileName

If Sfile = Empty Then
Exit Sub
End If

Me.MousePointer = vbHourglass

Set objE = GetObject(, "Excel.application")

If Err.Number <> 0 Then
Set objE = CreateObject(&quot;Excel.application&quot;)
blnR = False
Else
blnR = True
End If

objE.Workbooks.Add

Set objW = objE.ActiveSheet


strWrkSQL = &quot;Exec sp_RET_EMPTEL_GROUP1 &quot; & frmEmp.intUPID & &quot;, '&quot; & SDate.Value & &quot;', '&quot; & FDate & &quot;', &quot; & intGRP

Call X_DBS_Call1(strWrkSQL)

X = 1 + X
Do While (Not rsx1.EOF)

intTotCll = (intTotCll + rsx1!TCNT)
If (rsx1!CLID = 0) Then
intPvtCll = (rsx1!TCNT + intPvtCll)
Else
intClnCll = (intClnCll + rsx1!TCNT)
intDstCln = (intDstCln + 1)
End If

objW.Cells(X, 1).Value = rsx1!TNUM
objW.Cells(X, 2).Value = rsx1!TCNT
objW.Cells(X, 3).Value = rsx1!TCNA
objW.Cells(X, 4).Value = Format(rsx1!AVGD, &quot;HH:MM:SS:&quot;)
objW.Cells(X, 5).Value = rsx1!AVGC
objW.Cells(X, 6).Value = rsx1!CLID
objW.Cells(X, 7).Value = Trim(rsx1!CLIN) + &quot; &quot; + Trim(rsx1!CLSN)
If rsx1!CLND = &quot;1900/01/01&quot; Then
objW.Cells(X, 8).Value = &quot;&quot;
Else
objW.Cells(X, 8).Value = Format(rsx1!CLND, &quot;YYYY/MM/DD&quot;)
End If
objW.Cells(X, 9).Value = rsx1!EMPN

X = 1 + X
rsx1.MoveNext

Loop

cnx.Close
-------

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top