?
Solved

excel errors

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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

764 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