Solved

View/ Update/ Save Access in Excel form at VB

Posted on 2001-09-15
4
162 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
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

820 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