Discussion Locked

Database conversion

0 helpful
6 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I made a data entry program in Visual Basic using a MS ACCESS database. How am I going to convert this MS ACCESS database within my program at a press of a button (commandbutton), to an EXCEL format file to be accessible to a third-party software. Iwill highly appreciate immediate response. Thanks.

6 replies

by fenaikh

Hi

pls folow these steps to copy the MS Access records into MS Excel.

1- Go to Database window, select the table or query you want to export.
2- Go to the tools menu choose Office Links .
3- Go to the submenu or to the Office Links toolbar list Click Analyze It With Excel.
Good luck

Mohamed

by limbo

Good question,

Here's one programmatic solution I know works.

Get your resultsets in memory, then work through every single field in the following fashion (beware, this is pseudo-code):

' Dim 1Field
' Dim 1Row
' Dim 1Table

' For Row = 1 to ResultSet.RowCount
' For Col = 1 to ResultSet.ColumnCount

' 1Field = ResultSet.Field(Row,Col)

' If IsEmpty(1Field) Then
' 1Row = 1Row & ","
' Else
' If IsNumeric(1Field) Then
' 1Row = 1Row & 1Field & ","
' Else
' 1Row = 1Row & "'" 1Field & "',"
' End If
' End If
' Next Col

' Remove last comma, add a carriage return
' 1Row = Left(1Row, Len(1Row)-1) & vbCrLF

' Add this row to the output, and clear
' 1Table = 1Table & 1Row
' 1Row = Empty

' Next Row

Use a function like this & you will have a CSV array stored in the variable 1Table.

This CSV array when saved with the .XLS or .CSV file extension can be opened by any version of Excel.

To save it quickly display the variable 1Table in a RichTextBox and call it's save method.

If this isn't good enough you should consider passing the data driectly into the 'Excel.Application' object in VB.

I would give you asolution to do this but I don't have VB in front of me right now...Sorry.

But creating Comma Separated Values (CSV) is a tried and tested method of flat file data transfer, so it will work.

by limbo

You know I really wish this board didn't left justify code!!!

Sorry about that, it was indented correctly -honest...

This discussion is closed to new replies.