?
Solved

View/ Update/ Save Access in Excel form at VB

Posted on 2001-09-15
4
Medium Priority
?
168 Views
Last Modified: 2010-05-02
hi, i need help.

My table/database is the Access form, but I would like
to :->View it (in MS Excel form),
   :->Modify it (i means modify the data in MS Excel form without modifying
     my original MS Access database/table) and then
   :->Save it (at others location without overwrite my original table,
     and the it should save in MS Excel form.)

from my VB 6 application.

So, what control or anyting else i should used and learn??? Please help
me if you know....
0
Comment
Question by:CKWONGCHEEKEONG
  • 2
4 Comments
 
LVL 12

Accepted Solution

by:
roverm earned 600 total points
ID: 6484441
You can use office automatition.

This is how to get all data from one table in a sheet:

Private Sub Form_Load()
Dim oSheet As Excel.Worksheet
Dim oTable As Excel.QueryTable

    'try to get an open instance
    On Error Resume Next
    Set oExcel = GetObject("", "excel.application")
    If Err.Number <> 0 Then 'not found, create a new instance
        Set oExcel = CreateObject("excel.application")
    End If
   
    If oExcel Is Nothing Then
        MsgBox "Couldn't create/get Excel !", vbCritical
        Exit Sub
    End If
   
    Set oWorkbook = oExcel.Workbooks.Add
    Set oSheet = oWorkbook.Sheets.Add
   
    With oSheet
        Set oTable = .QueryTables.Add("ODBC;DSN=MS Access Database;DBQ=C:\Program Files\Microsoft Visual Studio\VB98\NWIND.MDB", _
            .Range("A1"), "Select * from Customers")
        oTable.Refresh
    End With
   
    oExcel.Visible = True
    oSheet.Activate

    Set oSheet = Nothing
    Set oTable = Nothing

End Sub

Then to save it:

Private Sub Command1_Click()
    oWorkbook.Save
    oExcel.Quit
    Set oWorkbook = Nothing
    Set oExcel = Nothing
    End
End Sub

And, of course, in the general section:

Option Explicit

Dim oExcel As Excel.Application
Dim oWorkbook As Excel.Workbook

D'Mzzl!
RoverM
0
 
LVL 12

Expert Comment

by:roverm
ID: 6484466
BTW:
In the example I provided, you have to set a reference to Microsoft Excel 9.0 Library.
This is for ealry binding. If you don't want that, just change the variables into Objects:

Dim oExcel As Object
and so...

D'Mzzl!
RoverM
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7208434
Hi CKWONGCHEEKEONG,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept roverm's comment(s) as an answer.

CKWONGCHEEKEONG, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 
LVL 5

Expert Comment

by:Netminder
ID: 7241246
Per recommendation, force-accepted.

Netminder
CS Moderator
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

600 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