473,396 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

export data from vb6 to excel using ado

I GOT CODE AFTER GOOGLING IT TO EXPORT DATA FROM VB6 TO EXCEL.CODE WORKS FINE BUT I AM ABLE TO EXPORT ONLY 26 FIELDS FROM RECORDSET.
ON ANOTHER FORM I HAVE 50 FIELDS AND THERE IS A PROBLEM I GET ERROR AT RUNTIME.

CODE:
Expand|Select|Wrap|Line Numbers
  1.  Dim i As Long
  2.  
  3.     On Error GoTo ErrorHandler
  4.  
  5.     Set oBook = oApp.Workbooks.Add
  6.     Set oWorkSheet = oBook.Worksheets.Item(1)
  7.  
  8.     oApp.Visible = False
  9.  
  10.     With oWorkSheet
  11.         c = Asc("A")
  12.         For Each oField In rs.Fields
  13.             .Range(Chr(c) & "1").Value = oField.Name
  14.             .Range(Chr(c) & "1").Font.Bold = True
  15.             c = c + 1
  16.         Next
  17.  
  18.         i = 2
  19.         'IF YOUR RECORDSET CURSOR LOCATION IS LOCAL, THEN REMOVE COMMENT FROM FOLLOWING LINE
  20.         'If rs.RecordCount > 0 Then rs.MoveFirst
  21.         rs.MoveFirst
  22.         While Not rs.EOF
  23.             c = Asc("A")
  24.             For Each oField In rs.Fields
  25.                 .Range(Chr(c) & i).Value = rs(oField.Name)
  26.                 c = c + 1
  27.             Next
  28.             i = i + 1
  29.             rs.MoveNext
  30.         Wend
  31.     End With
  32.  
  33.     oApp.Visible = True
  34.  
  35.     Exit Sub
  36.  
  37.     GoTo CleanExit
  38.  
  39. ErrorHandler:
  40.     MsgBox Err.Number & ": " & Err.Description
  41. CleanExit:
  42.     If Not oApp Is Nothing Then Set oApp = Nothing
  43.     If Not oBook Is Nothing Then Set oBook = Nothing
  44.     If Not oWorkSheet Is Nothing Then Set oWorkSheet = Nothing
  45. End Sub
Oct 28 '10 #1
2 5549
MikeTheBike
639 Expert 512MB
Hi

Of the top of my head, I woud say that on the 27th pass thought the loop it is trying to reference as cell with an address of "[#" instead of "AA#" (where # is some number!!)

ie Chr(91) = [

which is the Ascii characture after Z in then Ascii codes.

Therefore, as this won't work when you run out of alpherbet, I suggest something like this:-
Expand|Select|Wrap|Line Numbers
  1.     Dim c As Integer
  2.     Dim i As Integer
  3.  
  4.     With oWorkSheet
  5.         i = 1
  6.         For c = 0 To rs.Fields.Count - 1
  7.             .Cells(i, c + 1).Value = rs(c).Name
  8.             .Cells(i, c + 1).Font.Bold = True
  9.         Next
  10.  
  11.         rs.MoveFirst
  12.  
  13.         i = 2
  14.         While Not rs.EOF
  15.             For c = 0 To rs.Fields.Count - 1
  16.                 .Cells(i, c + 1).Value = rs(c)
  17.             Next
  18.             i = i + 1
  19.             rs.MoveNext
  20.         Wend
  21.     End With
HTH

MTB
Oct 29 '10 #2
Thanx,yeah this logic is working for me.
It really help me complete my form.
Oct 29 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Matt | last post by:
I have an ASP page that calls ASP routines that I created that execute a database query and return the results to a recordset. I then iterate through the recordset and display the data in a table....
2
by: Danny | last post by:
I am trying to export my access 2002 table to excel using transfer spreadsheet. It works fine but in excel, there is an apostrophe before each word in all cells. How can I avoid this? I tried...
1
by: vijay babu | last post by:
Hi, I'm developing asp.net web application and doing some part of the Export data to Excel using XMLSpreadSheet Language. But, I'm unable to set some new properties like autowidth for cell and...
4
by: Jiro Hidaka | last post by:
Hello, I would like to know of a fast way to export data source data into an Excel sheet. I found a way from C# Corner(Query Tool to Excel using C# and .NET) which is a neat little way of...
0
by: siLver | last post by:
Hi.. I'm trying to export to excel.. using: Response.ContentType = "application/vnd.ms-excel" Response.AddHeader "Content-disposition", "attachment;filename=" & sFileName Response.AddHeader...
3
by: ggupta78 | last post by:
Hi, Currently in our application we use the MHTML way of exporting to Excel i.e we render the datagrid HTML and set the MIME type to Excel. This works great but has the following limitation: 1....
5
by: harljef | last post by:
I need help with a PHP script code that could export to excel from a Oracle database I am using PHP4
1
by: CoolFactor | last post by:
MY CODE IS NEAR THE BOTTOM I want to export this Access query into Excel using a command button on an Access form in the following way I describe below. Below you will find the simple query I am...
3
by: =?Utf-8?B?YzY3NjIyOA==?= | last post by:
Hi all, I have a question for you. I have a .csv file which has many lines of data. Each line has many data fields which are delimited by ",". Now I need to extract part of data from this...
2
hemantbasva
by: hemantbasva | last post by:
Note We need to have a template on server for generating report in multiple sheet as we do not had msoffice on server moreover this require a batch job to delete excel file created by the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.