I'm trying to run an R Script from my access DB so it will process some data before it is imported, however i'm having trouble as it fails at the errrorCode on the last line.The scrip is:
Private Sub cmdRcode_Click()
Dim shell As Object
Set shell = VBA.CreateObject("WScript.Shell")
Dim waitTillComplete As Boolean: waitTillComplete = True
Dim style As Integer: style = 2
Dim errorCode As Integer
Dim path As String
path = "C:\Users\Liam\Dropbox (BGD_058)\BGD_058\19_BFI_data\Analysis\r_scripts\BFI_DAT_1.R"
errorCode = shell.Run(path, style, waitTillComplete)
End Sub
EDIT:
Upon advice from the comments i've changed my file path, avoid spaces and substituted the errorCode as follows:
path = "Rscript C:\Users\Documents\BFI_Field_Forms\R\BFI_DAT_1.R"
errorCode = shell.Run("C:\Users\R\BFI_DAT_1.R", 1, True)
I then updated the environment path to Advanced System Settings/Environment Variable and created a new variable called "PATH" with the line: C:\Program Files\R\R-3.2.2\bin\x64;
The result is that it opens my R file, however it does not run the R script. The priority is for it to run the script (so the data is processed), and if possible, the R file would not be visible to the user.
Any advice appreciated.