Import Excel Data to Access Table MACRO (1 Viewer)

santoshdream

Registered User.
Local time
Yesterday, 21:25
Joined
Jan 22, 2009
Messages
22
Hi All,

I want to Import Excel file data in Access Table on Submit Button click through code. I would appreciate if you could help me in this reqard. Please find the enclosed files for the reference.

In this file export button is working fine. But I am confused in
" How to write a code in on click button to import the excel data to access table automatically.


Need urgent help.

Santosh
:confused::confused::confused::confused::confused:
 

Attachments

  • macro.zip
    46.9 KB · Views: 1,301

santoshdream

Registered User.
Local time
Yesterday, 21:25
Joined
Jan 22, 2009
Messages
22
Hi,

I am trying to use the following code but its not working

My access table name is = DATA

File which I want to import name is = dps.xls

Private Sub Command3_Click()

Dim myfile As String, sql As String
Dim db As Database, rs As Recordset, rs_target As Recordset
Set db = DBEngine(0)(0)
'myfile = OpenFile("c:\d\", "xls", "*.xls", 0)
myfile = OpenFile("c:\d\", "dps", "*dps.xls", 0)
If myfile = "" Then
End
End If
DoCmd.SetWarnings False
DoCmd.RunSQL "delete * from DATA"
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "DATA", myfile ', , "Importfile!"
Set rs = db.OpenRecordset("DATA")

DoCmd.SetWarnings True

MsgBox "File has been imported "
End Sub

Thanks
 

Ron_dK

Cool bop aficionado
Local time
Today, 06:25
Joined
Sep 5, 2002
Messages
2,141
What's the error that you get ?

Btw.: better not name a table as DATA. Data is a preserved word in Acces which might give you errors.

Hth
 

santoshdream

Registered User.
Local time
Yesterday, 21:25
Joined
Jan 22, 2009
Messages
22
Error is showing....

COMPILE ERROR:
SUB OR FUNCTION NOT DEFINED


please find the enclosed print shot for the error
 

Attachments

  • error.doc
    78 KB · Views: 553

Users who are viewing this thread

Top Bottom