Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 167
  • Last Modified:

View/ Update/ Save Access in Excel form at VB

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
CKWONGCHEEKEONG
Asked:
CKWONGCHEEKEONG
  • 2
1 Solution
 
rovermCommented:
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
 
rovermCommented:
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
 
DanRollinsCommented:
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
 
NetminderCommented:
Per recommendation, force-accepted.

Netminder
CS Moderator
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now