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

Excel Object in Visual Basic...What am I doing wrong here?!!!!

Status
Not open for further replies.

Webrookie

Programmer
May 18, 2000
112
US
I have the Excel Object Library 9.0 added as a reference.&nbsp;&nbsp;It blows up as soon as it gets into the for loop.&nbsp;&nbsp;It gives me an error 1004:&nbsp;&nbsp;Cells Method of _Application object failed.&nbsp;&nbsp;<br><br>I know there is data in my recordset, rs_regid.&nbsp;&nbsp;Here's the code:<br><br><br>Dim ExcelSheet As excel.Application<br>Set ExcelSheet = New excel.Application<br>rs_regid.MoveFirst<br>For k = 1 To rs_regid.RecordCount<br>&nbsp;&nbsp;With ExcelSheet.Application<br>&nbsp;&nbsp;&nbsp;&nbsp;.Cells(k, 1).Value = rs_regid(&quot;reg_id&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;.Cells(k, 2).Value = rs_regid(&quot;fname&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;.Cells(k, 3).Value = rs_regid(&quot;lname&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;.Cells(k, 4).Value = rs_regid(&quot;mi&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;.Cells(k, 5).Value = rs_regid(&quot;degree&quot;)<br>&nbsp;&nbsp;End With<br>Next<br><br>MsgBox CurDir<br><br>datestmp = Format(Now, &quot;m/d/yy&quot;)<br>slashpos = InStr(1, datestmp, &quot;/&quot;)<br>sufmonth = Left(datestmp, slashpos - 1)<br>sufyear = Right(datestmp, 2)<br><br>ExcelSheet.SaveAs CurDir & &quot;\spreadsheets\faxsht&quot; & Trim(sufmonth) & Trim(sufyear)<br>ExcelSheet.Application.Quit<br>Set ExcelSheet = Nothing<br><br><br><br><br>PLEASE HELP ME
 
I don't know anything about programming excel,&nbsp;&nbsp;but I can tell you that unless you put a movenext inside your loop, every row will contain the values from the first record in the recordset <p>nick bulka<br><a href=mailto: > </a><br><a href= > </a><br>
 
let me see if I can clear something up here, first off excel is a SpreadSheet program, Access is a Database program<br>Access has records, Excel has Cells. Did I miss anything? or are the two just as easily used the same? <p>Karl<br><a href=mailto:kb244@kb244.8m.com>kb244@kb244.8m.com</a><br><a href= </a><br>Experienced in , or have messed with : VC++, Borland C++ Builder, VJ++6(starting),VB-Dos, VB1 thru VB6, Delphi 3 pro, Borland C++ 3(DOS), Borland C++ 4.5, HTML,Visual InterDev 6, ASP(WebProgramming), QBasic(least i didnt start with COBOL)
 
True enough, Karl, but those cells are arranged in rows and columns. <p>nick bulka<br><a href=mailto: > </a><br><a href= > </a><br>
 
good point, in other words, he's just not moving anywhere. <p>Karl<br><a href=mailto:kb244@kb244.8m.com>kb244@kb244.8m.com</a><br><a href= </a><br>Experienced in , or have messed with : VC++, Borland C++ Builder, VJ++6(starting),VB-Dos, VB1 thru VB6, Delphi 3 pro, Borland C++ 3(DOS), Borland C++ 4.5, HTML,Visual InterDev 6, ASP(WebProgramming), QBasic(least i didnt start with COBOL)
 
Ok, guys...<br><br>Nick, I did figure out that wasn't moving anywhere<br><br>Yes you can use excel like access.<br><br>The error had nothing to do with me not moving anywhere<br><br>I figure out what the problem was, I had to create a new workbook and use the cells method of the active sheet to insert the data.&nbsp;&nbsp;It's all working fine now.<br><br>Sorry I didn't get back sooner, but I was working on it.<br><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top