If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > excel to Access

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-17-04, 09:24
Alexxx12 Alexxx12 is offline
Registered User
 
Join Date: Sep 2002
Location: NJ
Posts: 139
excel to Access

Hi,

wind2k and xp
access 2k

I have this problem I can not seem to be able to resolve. It is urgent that I fix it for my project.
The code bellow is a test: It is to pick up the data from Titles tables in db1.mdb in the c:\ and put in the excel sheet. However it does not work and I am stuck. Please somebody help me.



Note:

When highliting the db it is set at 'nothing' I don't understand.
Code:
Private Sub CommandButton1_Click()
On Error Resume Next
   Dim db As Database
   Dim rs As Recordset
   Dim fld As Field
   Dim i As Integer
   
   Set db = OpenDatabase("c:\db1.mdb")
   Set rs = db.OpenRecordset("Titles", dbOpenDynaset, dbReadOnly)
   [A2].CopyFromRecordset rs
   
   For Each fld In rs.Fields
        i = i + 1
        Cells(1, i).Value = fld.Name
   Next fld
   ActiveSheet.Columns.AutoFit
   db.Close
    
End Sub
I have MS DAO 3.51 Object Library
MS Access 9.0 Object Library.
What other Libraries do I need to make this work?
Reply With Quote
  #2 (permalink)  
Old 09-23-04, 19:20
zacemmel zacemmel is offline
Registered User
 
Join Date: Sep 2004
Posts: 6
I would suggest using ADO (ActiveX Data Objects)
Reply With Quote
  #3 (permalink)  
Old 09-24-04, 08:35
MikeTheBike MikeTheBike is offline
Registered User
 
Join Date: Apr 2004
Location: Derbyshire, UK
Posts: 714
Hi

I would also use ADO not DAO given a free choice, but I have used DAO in the past, but I assume use use Access moslty?.

I think you need to add thses two line


Dim wrkJet As Workspace

Set wrkJet = CreateWorkspace("", "admin", "", dbUseJet)


and modify the OpenDatabase so

Set db = wrkJet.OpenDatabase("c:\db1.mdb")


It worked for me!


HTH

MTB
Reply With Quote
  #4 (permalink)  
Old 10-02-04, 10:32
n00bl0rd n00bl0rd is offline
Registered User
 
Join Date: Oct 2004
Posts: 8
hi, this should work fine,
the only refernce you need is to : MS DAO 3.6 Object Library

Code:
Private Sub CommandButton1_Click()
On Error Resume Next
   Dim db As DAO.Database
   Dim rs As DAO.Recordset
   Dim fld As DAO.Field
   Dim i As Integer
   
   Set db = OpenDatabase("c:\db1.mdb")
   Set rs = db.OpenRecordset("Titles", dbOpenDynaset, dbReadOnly)
   [A2].CopyFromRecordset rs
   
   For Each fld In rs.Fields
        i = i + 1
        Cells(1, i).Value = fld.Name
   Next fld
   ActiveSheet.Columns.AutoFit
   db.Close
    
End Sub
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On