[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

excel errors

Posted on 1998-08-12
2
Medium Priority
?
380 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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

650 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