Solved

View/ Update/ Save Access in Excel form at VB

Posted on 2001-09-15
4
164 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
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…
Suggested Courses
Course of the Month3 days, 17 hours left to enroll

630 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