Buckeye4Life
asked on
Macro Permission denied
I'm trying to run a function using a Macro. When I try to run the macro, I receive a Run-time error "70" Permission denied.
'
The error occurs at line :Open FileNameAndPath For Output Access Write Lock Write As FileNum
The Marco is basically is run code:
Function Name: Export_Tab_Delimited ( "tblAGRSalesProjection", "F:\Supply Chain\Team Folders\Metrics\AGR Sales Projection\tblAGRSalesProj ection.txt ")
'
The error occurs at line :Open FileNameAndPath For Output Access Write Lock Write As FileNum
The Marco is basically is run code:
Function Name: Export_Tab_Delimited ( "tblAGRSalesProjection", "F:\Supply Chain\Team Folders\Metrics\AGR Sales Projection\tblAGRSalesProj
Option Compare Database
Option Explicit
Public Function Export_Tab_Delimited(TableOrQueryName As String, FileNameAndPath As String)
'This uses the DAO database reference. IN the VB window (Ctrl+G) go to _
Tools --> References and select the Microsoft DAO 3.6 Library
Dim DB As DAO.Database
Dim RS As DAO.Recordset
Dim I As Integer
Dim FileNum As Integer
'Dim FileNameAndPath As String
Dim OutputLine As String
FileNum = FreeFile()
'FileNameAndPath = "F:\Supply Chain\Team Folders\Metrics\AGR Sales Projection\tblAGRSalesProjection1.txt"
Set DB = CurrentDb() 'Use the current database
Set RS = DB.OpenRecordset("qryAGRSalesProjection") 'actually open the recordset
If RS.EOF = False Then
RS.MoveFirst
Else
MsgBox "No Data", vbExclamation, "Exiting Fuction"
Set RS = Nothing
Set DB = Nothing
Exit Function
End If
'Open the file for output
Open FileNameAndPath For Output Access Write Lock Write As FileNum
I = 0
OutputLine = ""
'Output the field names as a header
For I = 0 To RS.Fields.Count - 1
If I > 0 Then
OutputLine = OutputLine & Chr(9) & RS.Fields(I).Name
Else
OutputLine = RS.Fields(I).Name
End If
Next I
Print #FileNum, OutputLine
Debug.Print OutputLine
I = 0
OutputLine = ""
'start outputting the data
Do Until RS.EOF
For I = 0 To RS.Fields.Count - 1
If I > 0 Then
OutputLine = OutputLine & Chr(9) & RS.Fields(I).Value
Else
OutputLine = RS.Fields(I).Value
End If
Next I
Print #FileNum, OutputLine
Debug.Print OutputLine
OutputLine = ""
RS.MoveNext
Loop
Close #FileNum
Set RS = Nothing
Set DB = Nothing
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Lol - no probs, glad it helped - (bosses - always trying to be helpful... tssk!!)
ASKER