Solved

View/ Update/ Save Access in Excel form at VB

Posted on 2001-09-15
4
159 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 150 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Per recommendation, force-accepted.

Netminder
CS Moderator
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now