I was capable of opening an excel worksheet from my project but nothing appeared on the sheet, The fields and the recordsets could not bet seen, I used the following code:
Dim strExcelFile As String
Dim strWorksheet As String
Dim strDB As String
Dim strTable As String
Dim Conn As ADODB.Connection
Dim query As String
Set Conn = New ADODB.Connection
Dim certNo As Integer
Conn.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & "Fixed Asset Register.mdb" & ";"
Conn.Open
Dim xlobj As Excel.Application
Set xlobj = CreateObject("Excel.Application")
Dim xFile As String
xFile = txtFi2Name.Text
xlobj.Workbooks.Add
xlobj.ActiveWorkbook.SaveAs FileName:= _
"D:Documents and SettingsuserMy Documentsvb_project_AccessToExcel" + xFile
xlobj.DisplayAlerts = False
xlobj.Visible = True
Please Help me see the recordset on the sheet!
I'm still an infant programmer guyz av brainedstormed enough to deserve an aid by you proffesionals please
hoping to hear from you soon
its been long since i began struggling for help on programming in Visual Basic 6.0 but my problem has come to an end since i joined this site. its amazing guyz!!!!!!
sirbus_gents@yahoo.com
(Programmer/Analyst)
The code is totally self explanatory, In the load event we're going to open the new instance of the excel library and our excel file “book1.xls” will be accessible from our code. Then we'll use Command1 to retrieve data from book1, please note that you must have some data in the excel file. Similarly Command2 is used to put/replace the data in the excel sheet cells.
'do declare these variables you need to add a reference
'to the microsoft excel 'xx' object library.
'you need two text boxes and two command buttons
'on the form, an excel file in c:\book1.xls
Dim xl As New Excel.Application
Dim xlsheet As Excel.Worksheet
Dim xlwbook As Excel.Workbook
Private Sub Command1_Click()
'the benifit of placing numbers in (row, col) is that you
'can loop through different directions if required. I could
'have used column names like "A1" 'etc.
Text1.Text = xlsheet.Cells(2, 1) ' row 2 col 1
Text2.Text = xlsheet.Cells(2, 2) ' row 2 col 2
'don't forget to do this or you'll not be able to open
'book1.xls again, untill you restart you pc.
xl.ActiveWorkbook.Close False, "c:\book1.xls"
xl.Quit
End Sub
Private Sub Command2_Click()
xlsheet.Cells(2, 1) = Text1.Text
xlsheet.Cells(2, 2) = Text2.Text
xlwbook.Save
'don't forget to do this or you'll not be able to open
'book1.xls again, untill you restart you pc.
xl.ActiveWorkbook.Close False, "c:\book1.xls"
xl.Quit
End Sub
Private Sub Form_Load()
Set xlwbook = xl.Workbooks.Open("c:\book1.xls")
Set xlsheet = xlwbook.Sheets.Item(1)
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set xlwbook = Nothing
Set xl = Nothing
End Sub
My problem has come to an end since i joined this site. its amazing.A big thanx to the person who came up with this idea. I love you and keep it up.This is the the place to be if you are an ICT student and need to developed your skills in square .
achieng
jkuat
Pages
Add new comment