Solved

excel errors

Posted on 1998-08-12
2
352 Views
Last Modified: 2012-06-27
Dim db As Database
  Dim rs As Recordset
  Dim wb As Object
  Dim qstr7 As String
     
  Set db = OpenDatabase("c:\stock.mdb")
  Set wb = GetObject("c:\book1.xls")

  qstr7 = " Insert into nice_rpt " _
             & "select Description.StockCardNo, Description.Description, Product.Specifications, Received_On.DateReceived, Received_On.QtyReceived, Received_On.UnitPrice, Received_On.BillNumber from Description, Product, Received_On where Description.StockCardNo = Product.StockCardNo and Product.ProductID = Received_On.ProductID order by Product.ProductID "
 
  db.Execute qstr7
 
  Set rs = db.OpenRecordset("nice_rpt")
 
  With wb
  .Sheets("sheet1").Select
  .Sheets("sheet1").Cells.ClearContents
  .Sheets("sheet1").Range("A1").CopyFromRecordset rs
  .Parent.Windows("book1.xls").Visible = True
  .Save
  .Close
  End With

  Set wb = Nothing
  Set rs = Nothing

i got a
runtime error '-2147417851 (80010105)';
method 'copyfromrecordset' of object 'Range' failed
can anyone tell me what's wrong?
0
Comment
Question by:nightrage
2 Comments
 
LVL 1

Accepted Solution

by:
chdy earned 50 total points
ID: 1468607
Dear nightrage!..
I not use above Program Source to relate with Excel Applicaton.

i often use below method....

'#########################################3
Option Explicit
Dim ws As Workspace
Dim db As Database
Dim rs As Recordset

Dim ExcelSheet As Object
Dim WorkSheets
Dim WorkSheet As Integer

Dim sSql$

Private Sub mnuSave_Click()
Dim iRCnt%

Set ws = Workspaces(0)

Set db = ws.OpenDatabase("d:\excute\Sample.mdb")

sSql = "select * from Machine1"

Set rs = db.OpenRecordset(sSql)

Set Data1.Recordset = rs
   
iRCnt = rs.RecordCount

    With ExcelSheet
        If WorkSheet > 1 Then
            .WorkSheets.Add
        End If
        .Application.Visible = True

        Dim N As Integer
        Dim XName1 As String, XName2 As String, XName3 As String, XName4 As String
       
        If iRCnt = 0 Then Exit Sub
        .WorkSheets(1).range("A1").Value = "COUNT"
        .WorkSheets(1).range("B1").Value = "START TIME"
        .WorkSheets(1).range("C1").Value = "END TIME"
        .WorkSheets(1).range("D1").Value = "TERM"
       
        rs.MoveFirst
       
        For N = 0 To iRCnt - 1
            XName1 = "A" + Format(N + 2)
            XName2 = "B" + Format(N + 2)
            XName3 = "C" + Format(N + 2)
            XName4 = "D" + Format(N + 2)
           
            .WorkSheets(1).range(XName1).Value = rs.Fields("sNum")
            .WorkSheets(1).range(XName2).Value = rs.Fields("sBStartT")
            .WorkSheets(1).range(XName3).Value = rs.Fields("sBEndT")
            .WorkSheets(1).range(XName4).Value = rs.Fields("sTerm")
         rs.MoveNext
        Next N
       
        WorkSheet = WorkSheet + 1
   
    End With

End Sub

Private Sub Form_Load()
   
Set ExcelSheet = CreateObject("Excel.sheet")
WorkSheet = 1

End Sub

Private Sub Form_Unload(Cancel As Integer)
    Set ExcelSheet = Nothing
End Sub

'############################################
i think that your problem is Automatic Erorr...
Perhaps, link Excel.
0
 

Author Comment

by:nightrage
ID: 1468608
u know how to set the font in the cell to align to center?

i tried worksheets(!).range("A2").select.horizontalAlignment = xlCenter
and it said xlCenter is a undefine variable

0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now