ใส่ความเห็น

VB 6.0 Copy database from Access to Excel +Explanation


””Click start to tranfer data from ms.Access to Ms.Excel
Private Sub cmb1_Click()
call printer2
End Sub
”””””””””””””””””””””””’
””’Start Copy data”””””””””””””’
Private Sub printer2()
‘Create a Recordset from all the records in the Orders table
Dim sNWind As String
Dim conn As New ADODB.Connection
Dim rs As ADODB.Recordset
sNWind = _
“E:\Asset System\MTP13DB.mdb”
conn.Open “Provider=Microsoft.Jet.OLEDB.4.0;Data Source=” & _
sNWind & “;”
””””Call Database access from Address ”””””’
conn.CursorLocation = adUseClient
Set rs = conn.Execute(“tblOrder”, , adCmdTable)
””””’call tblorder from access to copy all data””””””’
‘Create a new workbook in Excel
Dim oExcel As Object
Dim oBook As Object
Dim oSheet As Object
Set oExcel = CreateObject(“Excel.Application”)
Set oBook = oExcel.Workbooks.Open(FileName:=”E:\Asset System\Order.xls”)
Set oSheet = oBook.Worksheets(1)

‘Transfer the data to Excel start at cell A5
oSheet.Range(“A5”).CopyFromRecordset rs

‘Save the Workbook and Quit Excel
oBook.SaveAs “E:\Book2.xls”
oExcel.Quit

‘Close the connection
rs.Close
conn.Close
MsgBox “Parts data already saved at E:\Book2.xls”, vbOKOnly + vbInformation, “Status Report”
Call printer ‘call to print to printer
End Sub

”””””””’
Private Sub printer()
Dim xlApp As excel.Application
Dim xlWB As excel.Workbook
Dim xlSH As excel.Worksheet
‘open excel application
Set xlApp = New excel.Application
‘Open excel workbook
Set xlWB = xlApp.Workbooks.Open(FileName:=”E:\Book2.xls”)
‘There are two ways to access specific worksheets
‘By index number (the first worksheet in this case)
Set xlSH = xlWB.Worksheets(1)
‘or by the Sheet’s Name
‘ Set xlSH = xlWB.Worksheets(“TestSheet”)

PrintSheet xlSH, Now(), ” ”

‘Close workbook (optional)
‘xlWB.Close
‘Quit excel (automatically closes all workbooks)
‘xlApp.Quit
‘Clean up memory (you must do this)

‘Exel.Quit
End Sub
Sub PrintSheet(sh As Worksheet, strFooter As String, strHeader As String)

sh.PageSetup.CenterFooter = strFooter
sh.PageSetup.CenterHeader = strHeader
sh.PrintOut
‘MsgBox “Printing report. Thank you!”
End
‘Set xlWB = Nothing
‘Set xlApp = Nothing ‘ ” yyyy no data yet”, vbOKOnly + vbInformation, “Status Report”
End Sub

ใส่ความเห็น

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / เปลี่ยนแปลง )

Twitter picture

You are commenting using your Twitter account. Log Out / เปลี่ยนแปลง )

Facebook photo

You are commenting using your Facebook account. Log Out / เปลี่ยนแปลง )

Google+ photo

You are commenting using your Google+ account. Log Out / เปลี่ยนแปลง )

Connecting to %s

แปลเพลง VB 6.0 VB 2010 source code

VB2010 แปล แปลเพลง เนื้อเพลง VB 6.0 โหลดเพลงฟรี โหลดเพลง โหลด Mediafire เพลงลูกทุ่ง เพลงใหม่ เพลงลูกทุ่งมาใหม่ เพลงมันส์ โหลดเพลง free เพลงสตริง สตริง

Pathrix's Blog

journal and other stories

%d bloggers like this: