troubleshooting Question

Access to Excel

Avatar of joeserrone
joeserrone asked on
Microsoft Access
5 Comments1 Solution262 ViewsLast Modified:
I have the following code that is intended to take the information from a MS Access Table to a preformatted Excel spreadsheet on my desktop called Export.xls that has some protections in various fields. When I try running it I get the debugging error message "Compile Error: User-defined type not defined"

Any suggestions how to resolve this?

Private Sub Command11_Click()
Dim objXL As Excel.Application
Dim objWkb As Excel.Workbook
Dim objSht As Excel.Worksheet
Dim db As Database
Dim rs As Recordset
Dim intLastCol As Integer
Const conMAX_ROWS = 20000
Const conSHT_NAME = "myImport"
Const conWKB_NAME = "C:\users\joe\desktop\Export.xls"
  Set db = CurrentDb
  Set objXL = New Excel.Application
  Set rs = db.OpenRecordset("myImport", dbOpenSnapshot)
  With objXL
    .Visible = True
    Set objWkb = .Workbooks.Open(conWKB_NAME)
    'Give book a new name
    'objWkb.SaveAs "NewName.xlsx"
    Set objSht = objWkb.Worksheets(conSHT_NAME)

    With objSht
      .Range("A2").CopyFromRecordset rs
    End With
  End With
  Set objSht = Nothing
  Set objWkb = Nothing
  Set objXL = Nothing
  Set rs = Nothing
  Set db = Nothing

End Sub
NorieAnalyst Assistant
Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros