Solved

excel errors

Posted on 1998-08-12
2
357 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

929 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

11 Experts available now in Live!

Get 1:1 Help Now