Thanks Roy,
The error message I get is, "1004 Application-defined or object-defined error". This is the code that throws the error:
Sub risks_Issues()
On Error GoTo HandleErr
' Set file path, database name and query name for ado connection and command
strPath = "\\10.233.9.110\share\RevenueCycle\KPIT NATL PMO\RC PMO Planning\PMOS\IssueRiskDatabase\Template"
strPath = strPath & "\IssueRisk_v2007.accdb"
strMessage = "No Risks and Issues records returned."
nrRisksIssues = 0
' Pick appropriate query based on region selection
Select Case Properties.Range("D2").Value
Case "GLOBAL"
strQry = "qry_S_IssueRiskDashboard_Global"
Case "ROCS"
strQry = "qry_S_IssueRiskDashboard_ROCS"
Case Else
strQry = "qry_S_IssueRiskDashboard_Regional"
End Select
' Call the parameters function
Call parameters(strQry)
' Call the connection function.
If conn(strPath, strQry) <> 1 Then
MsgBox "There was an error connecting to the database.", vbCritical, "Risks & Issues"
Exit Sub
End If
Application.ScreenUpdating = False
' Refresh the details data
'RisksIssuesDetails.Activate
With RisksIssuesDetails
' Find the last populated column and row
lColRi = .Range("A3").End(xlToRight).Column
lRowRi = .Range("A65536").End(xlUp).Row
' If no records returned - set nr flag, inform, clear out old data and exit
If rs.BOF = True And rs.EOF = True Then
nrRisksIssues = 1
Call noRecords(strMessage)
' Clean up
cn.Close
Set cn = Nothing
Set rs = Nothing
Set cmd = Nothing
Application.ScreenUpdating = True
Exit Sub
End If
' Clear out the old details data and paste out new data
If lRowRi < 4 Then ' If there's no data, paste out the new data from the Access query
.Range("A4").CopyFromRecordset rs
Else
.Range(Cells(4, 1), Cells(lRowRi + 1, lColRi)).Clear
.Range("A4").CopyFromRecordset rs ' Paste out the new data from the Access query
End If
' Find the new last populated column and row
lColRi = .Range("A3").End(xlToRight).Column
lRowRi = RisksIssuesDetails.Range("A65536").End(xlUp).Row
' Clear text-to-column errors in ProjectID and IssueRiskId cols F & I
.Range("I4:I" & lRowRi).TextToColumns
' Add cell borders
With .Range(Cells(4, 1), Cells(lRowRi, lColRi)).borders
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
' Clean up display
.Range("A1").Select
ActiveWindow.ScrollColumn = 1
ActiveWindow.ScrollRow = 1
End With
Application.ScreenUpdating = True
Application.CutCopyMode = False
ExitHere:
' Clean up object variables
cn.Close
Set cn = Nothing
Set rs = Nothing
Set cmd = Nothing
Exit Sub
HandleErr:
MsgBox Err.Description, , Err.Number
Resume ExitHere
Resume
End Sub
I commented out the line where I activate the worksheet so it would error out. The number of rows varies depending on the parameters selected. Is there any other way to clear cells, add borders, etc without selecting or activating the worksheet?
Thanks,
Jeff
Bookmarks