help with code please

mojo
09-01-2000, 06:17 AM
I have the following code behind a command button:


Dim rwIndex As Integer
Dim DB As Database, RS As Recordset
Dim StartCell As Range
Dim XLApp As New Excel.Application
XLApp.Workbooks.Open ("C:jobtracker emp.xls")

Set DB = OpenDatabase("C:jobtrackerjobtracker.mdb")
Set RS = DB.OpenRecordset("jobtracker")
Set StartCell = XLApp.Worksheets(1).Range("A4")
RS.MoveFirst
For x = 0 To RS.RecordCount - 1
With StartCell
If RS.Fields("username").Value = TBUsername.Text And RS.Fields("completed").Value = "" Then
.Offset(x, 0).Value = RS.Fields("jobnumber").Value
.Offset(x, 1).Value = RS.Fields("username").Value
.Offset(x, 2).Value = RS.Fields("clientname").Value
.Offset(x, 3).Value = RS.Fields("duedate").Value
.Offset(x, 4).Value = RS.Fields("budget").Value
.Offset(x, 5).Value = RS.Fields("partner").Value
.Offset(x, 6).Value = RS.Fields("description").Value
End If
End With
RS.MoveNext
Next
RS.Close
DB.Close

XLApp.Application.Visible = True
GoTo theend

I am trying to copy individual records from a recordset (table) into rows of an excel spreadsheet. But the records refuse to copy into the s/sheet.

Does anybody have any ideas why?

Any help is much appreciated (you are doing a great job here...thanks)

Dion

Valkyrie
09-13-2000, 04:02 PM
Mojo....I ran the code and it worked fine however, I made some slight changes. Since I was too lazy to create the MDB and link to it I simply replaced the values with letters of the alphabet A-G. I ran the code and sure enough I saw the letters A - G in columns A-B on row 4.

Having confirmed the copy funtion is working properly check the values in your recordsets. It could be that the recordset is returning null values which accounts for the empty cells! Run it with the debugger on to ensure there is actually values in the RS.Fields code. If yes then let me know how you are connecting to the DB (ADO vs DAO) as it wasn't obvious for me and I will try it with the complete code.

HTH /images/icons/smile.gif



Quote of the moment....
"My job is so top secret even I don't know what I'm doing!"

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum