troubleshooting Question

Error with Index, ENVIRON and EXCEL.exe

Avatar of Nagender Reddy
Nagender Reddy asked on
Microsoft OfficeDatabases
3 Comments1 Solution110 ViewsLast Modified:
dear team,
I am using office 2016.
i have developed a database using office 2016.
after deploying my end users (uses office 2013 ) facing issues with application.
1. on opening database . It is popup with  " searching for referenced file EXCEL.exe ".
2. HERE IS THE CODE FOR YOUR REFERENCE.
********************************************************************************************************************************
Option Compare Database
Private Sub cmdchemicalsearchexport_Click()
 Dim saveloc As String, strWorksheetPath As String, xl As Object, wb As Object
    Dim exportsheet As Object, Header As Variant, OIHeader As Variant
    'Dim db As DAO.Database, ExportRecordSet As DAO.Recordset
Dim db As Database
Set db = CurrentDb
Dim rs As Recordset
    saveloc = Environ("USERPROFILE") & "\Desktop\"
    saveloc = strWorksheetPath & "ChemicalSearchReport.xlsx"
    Set xl = CreateObject("Excel.Application")
    Set wb = xl.Workbooks.Add
    Set exportsheet = wb.Worksheets(1)
    exportsheet.Name = "Chemical Search"
    xl.Application.Visible = True
   Set rs = db.OpenRecordset(Me.RecordSource)
        exportsheet.Cells(1, 1).Value = "Trade Name"
        exportsheet.Cells(2, 1).Value = "Supplier"
        exportsheet.Cells(3, 1).Value = "Category"
        exportsheet.Cells(4, 1).Value = "Physical Appearance"
        exportsheet.Cells(5, 1).Value = "Active Ingredient"
        exportsheet.Cells(6, 1).Value = "Regional Availability"
        exportsheet.Cells(7, 1).Value = "EPA#"
        exportsheet.Cells(8, 1).Value = "Comment"
        exportsheet.Range("A1:A8").Font.Bold = True
    Dim rownum As Long, colnum As Long
    Dim i As Long
    i = 0
    rownum = 1
    colnum = 2
    rs.MoveFirst
    For Index = 1 To rs.Fields.Count
    If rs.Fields(i).Name <> "SDS" And rs.Fields(i).Name <> "CID" Then
        Do While Not rs.EOF
        exportsheet.Cells(rownum, colnum).Value = rs.Fields(i).Value
        rs.MoveNext
        colnum = colnum + 1
        Loop
        rownum = rownum + 1
        colnum = 2
    End If
    i = i + 1
    rs.MoveFirst
    Next
  With exportsheet
  .Cells(1, i).Select
   Set testRange = .Range(.Cells(1, 1), .Cells(i - 2, i + 1))
 End With
  testRange.Borders.LineStyle = xlContinuous
exportsheet.Cells.EntireColumn.AutoFit
    End Sub
********************************************************************************************************************************
ERROR 1 :
POINTING to Environ(saveloc = Environ("USERPROFILE") & "\Desktop\")
Compile error:
Can't find project or library
ERROR 2:
I HAVE COMMENTED i.e 'saveloc = Environ("USERPROFILE") & "\Desktop\"
pointing to  Index ( for your referecne For Index = 1 To rs.Fields.Count)
Can't find project or library
ASKER CERTIFIED SOLUTION
NorieSenior Associate
Join our community to see this answer!
Unlock 1 Answer and 3 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 3 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