?
Solved

excel errors

Posted on 1998-08-12
2
Medium Priority
?
384 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 150 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

840 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