I have been struggling to output the PDF report to the relevant folder within the server. The error which is showing is
RunTime error 3201, no record found.
Could you please help me to solve it?
Dim RFQNumber As String
Dim InNumber As String
Dim FullReportName As String
Dim path1 As String
RFQNumber = [Forms]![RFQ_Database]![RFQ_ExNumber]
InNumber = [Forms]![RFQ_Database]![RFQ_InNumber]
path1 = "\\AZBAK-FP02\Work\Old Server Data\V&C\" & RFQNumber & "\" & RFQNumber & " " & InNumber & ".pdf"
MsgBox (path1)
DoCmd.OutputTo acOutputReport, "AOrderFCAVienna", "PDFFormat(*.pdf)", path1, False
I believe the ampersand in the directory path is causing the issue.
ath1 = "\\AZBAK-FP02\Work\Old Server Data\V&C\" & RFQNumber & "\" & RFQNumber & " " & InNumber & ".pdf"
^^^
you may need to add chr code
ath1 = "\\AZBAK-FP02\Work\Old Server Data\V" & Chr(38) & "C\" & RFQNumber & "\" & RFQNumber & " " & InNumber & ".pdf"
Inserting a formula containing an ampersand into a cell
Related
I am using cells as the file path and filename to save a copy of my workbook.
Here's the code am using now but it puts spaces in between each cell.
Note only the ActiveSheet.Range cells will have the possibility of being blank
Dim NewWb As Workbook
sFile = Control_Sheet_VB.Range("H2") & "\" & ActiveSheet.Range("H8") & " " & ActiveSheet.Range("E10") & " " & ActiveSheet.Range("D14") & " - Ticket #" & Control_Sheet_VB.Range("B2") & Control_Sheet_VB.Range("C2") & ".xlsm"
Set OldWb = ActiveWorkbook
OldWb.SaveCopyAs sFile
Set NewWb = Workbooks.Open(sFile)
How can I make it so if some of the cells that are used as the file name are blank then it dose not put the extra space in the filename
you may go like this:
sFile = Control_Sheet_VB.Range("H2") & "\" & _
IIf(ActiveSheet.Range("H8") <> "", ActiveSheet.Range("H8") & " ", "") & _
IIf(ActiveSheet.Range("E10") <> "", ActiveSheet.Range("E10") & " ", "") & _
IIf(ActiveSheet.Range("D14") <> "", ActiveSheet.Range("D14") & " ", "") & _
" - Ticket #" & Control_Sheet_VB.Range("B2") & _
Control_Sheet_VB.Range("C2") & ".xlsm"
I'm able to use the below code to download files from server. However, this does tell me whether the files are downloaded successfully.
Sub DownloadFirstRunFilesPart2()
Application.StatusBar = "Downloading files..."
Dim wsh As Object
Dim errorcode4 As Integer
Dim cmd5 As Variant
Dim FirstRunFiles(5) As Variant
Dim var As Variant
FirstRunFiles(0) = ProN & "_KSParameter_UserInput.xlsx"
FirstRunFiles(1) = ProN & "_KSParameter_SysOutput.xlsx"
FirstRunFiles(2) = ProN & "_ModelParameter_UserInput.xlsx"
FirstRunFiles(3) = ProN & "_ModelParameter_SysOutput.xlsx"
FirstRunFiles(4) = ProN & "_VarClusParameter_UserInput.xlsx"
FirstRunFiles(5) = ProN & "_VarClusParameter_SysOutput.xlsx"
For Each var In FirstRunFiles
cmd5 = Chr(34) & "C:\Program Files (x86)" & "\PuTTY\pscp.exe" & Chr(34) & " -sftp -l " & pUser & " -pw " & pPass & _
" " & " " & pHost & ":" & ServerPath & "/" & var & " " & LocalPath & "\"
Set wsh = CreateObject("wscript.shell")
errorcode4 = wsh.Run(cmd5, vbHide)
'If errorcode4 = 0 Then MsgBox ("Error occurs. Fail to download " & var)
Next var
Application.StatusBar = "Download complete"
MsgBox ("Downloading process complete.")
End Sub
My error code always equals 0 no matter the file exists or not. How should I change this program?
Thanks in advance!
Update:
The new code that I tried:
Sub test()
Dim wsh As Object
Dim WshShellExec As Variant
Dim cmd3 As String
Dim pFirstRunFile1 As String
Const WshFinished = 1
Const WshFailed = 2
pFirstRunFile1 = "this_proj_name.txt"
cmd3 = Chr(34) & "C:\Program Files (x86)" & "\PuTTY\pscp.exe" & Chr(34) & " -sftp -l " & pUser & " -pw " & pPass & _
" " & " " & pHost & ":" & ServerPath & "/WOE/" & pFirstRunFile1 & " " & LocalPath & "\WOE"
Set wsh = CreateObject("wscript.shell")
WshShellExec = wsh.Exec(cmd3)
Select Case WshShellExec.Status
Case WshFinished
strOutput = WshShellExec.StdOut.ReadAll
Case WshFailed
strOutput = WshShellExec.StdErr.ReadAll
End Select
MsgBox strOutput 'write results in a message box
End Sub
However I'm getting error on this line:
WshShellExec = wsh.Exec(cmd3)
The error message says "Object does not support this property or method". Any ideas?
Here is the code, please help! I'm so lost. It successfully goes through each ID in the database.txt but every time it throws the exception and reports cannot download. I'm at my wits end, I've tried changing this so many times but nothing. The idea here is to download a file based on the date and the user id.
If its not found - catch the exception, if it is found - print in the datagridview.
Loop until all the IDs have been read.
Dim myDate = Format(DateTimePicker2.Value, "yyyyMMdd")
Do Until DateTimePicker2.Value > DateTimePicker3.Value
For Each strID As String In System.IO.File.ReadAllLines("database.txt")
Try
My.Computer.Network.DownloadFile("ftp://user:pass#ftp.ftp.net/" & strID & "/" & myDate & ".txt", My.Application.Info.DirectoryPath & "\logs\" & strID & "\" & Format(DateTimePicker2.Value, "yyyyMMdd") & ".txt")
Catch nullDownload As System.Net.WebException
MsgBox("File " & strID & "\" & Format(DateTimePicker2.Value, "yyyyMMdd") & ".txt could not be downloaded")
End Try
If My.Computer.FileSystem.FileExists(My.Application.Info.DirectoryPath & "\logs\" & strID & "\" & Format(DateTimePicker2.Value, "yyyyMMdd") & ".txt") Then
For Each line As String In
System.IO.File.ReadAllLines(My.Application.Info.DirectoryPath & "\logs\" & strID & "\" & Format(DateTimePicker2.Value, "yyyyMMdd") & ".txt")
DataGridView1.Rows.Add(line.Split(","))
Next
End If
Next
DateTimePicker2.Value = DateTimePicker2.Value.AddDays(1)
Loop
If DateTimePicker2.Value > DateTimePicker3.Value Then
MsgBox("Download complete.")
End If
EDIT: Just wanted to clear some things up...this fails to download ANYTHING. Even if the file exists. I can pull the existing file using a separate function in my application so I know it works and I know the downloading code works. Something is just missing here...
Also for clarity the file address should be ftp://ftp.ftp.net/ID9999/20150718.txt
HUZZAH! It was the date. by using the date as a variable, it fails.
Instead of
My.Computer.Network.DownloadFile("ftp://user:pass#ftp.ftp.net/" & strID & "/" & myDate & ".txt", My.Application.Info.DirectoryPath & "\logs\" & strID & "\" & Format(DateTimePicker2.Value, "yyyyMMdd") & ".txt")
I use
My.Computer.Network.DownloadFile("ftp://user:pass#ftp.ftp.net/" & strID & "/" & Format(DateTimePicker2.Value, "yyyyMMdd") & ".txt", My.Application.Info.DirectoryPath & "\logs\" & strID & "\" & Format(DateTimePicker2.Value, "yyyyMMdd") & ".txt")
I have written the code below, currently it creates a folder. However I would like to save the same word doc to that folder. Any pointers on where I am going wrong??
Thanks
Sub newfold()
Dim strNewFolderName As String
strNewFolderName = "New Folder " & (Month(Now())) & " " & Year(Now)
If Len(Dir("c:\Users\Jabaar\Documents\" & strNewFolderName, vbDirectory)) = 0 Then
MkDir ("c:\Users\Jabaar\Documents\" & strNewFolderName)
End If
Dim PathName As String
PathName = ("New Folder " & MonthName(Month(Now())) & " " & Year(Now))
ActiveDocument.SaveAs "c:\Users\Jabaar\Documents\" & "(strNewFolderName)" + ".doc"
End Sub
Just replace
ActiveDocument.SaveAs "c:\Users\Jabaar\Documents\" & "(strNewFolderName)" + ".doc"
with
ActiveDocument.SaveAs FileName:="c:\Users\Jabaar\Documents\" & strNewFolderName & "\" & Split(ActiveDocument.Name, ".")(0) & ".doc", _
FileFormat:=wdFormatDocument
where Split(ActiveDocument.Name, ".")(0) takes current name of file without extension. You could replace it with desired name:
ActiveDocument.SaveAs FileName:="c:\Users\Jabaar\Documents\" & strNewFolderName & "\" & "newFile.doc", _
FileFormat:=wdFormatDocument
This is what have done and it seems work.
ActiveDocument.SaveAs "c:\Users\Jabaar\Documents\" & strNewFolderName & "\" & "test" + ".doc
The solution #simoco provided is what I was looking for, so thanks for confirming the formatting of it #simoco
I am working on VBA, from which I have to call a vbscript by passing some values.
Here is the code:
''VBA
'Below values are on different cells of Excel file which I am reading
'into a global variable then pass it to vbscript.
'SFilename = VBscript file path
'QClogin = "abc"
'QCpassword = "abc"
'sDomain = "xyz"
'sProject = "xyz123"
'testPathALM = "Subject\xyz - Use it!\xyz_abc"
'QCurl = "http://xxx_yyy_zzz/qcbin/"
Set wshShell = CreateObject("Wscript.Shell")
Set proc = wshShell.exec("wscript " & SFilename & " " & QClogin & _
" " & "" & QCpassword & " " & "" & sDomain & " " & "" & sProject & _
" " & "" & testPathALM & " " & "" & QCurl & "")
''VBscript on some location
Dim strUserName, strPassword, strServer
strUserName = WScript.Arguments(0) '"abc"
Msgbox "strUserName : " & strUserName
strPassword = WScript.Arguments(1) '"abc"
Msgbox "strPassword : " & strPassword
strServer = WScript.Arguments(5) '"http://xxx_yyy_zzz/qcbin/"
Msgbox "strServer : " & strServer
Dim strDomain, strProject, strRootNode
strDomain = WScript.Arguments(2) '"xyz"
Msgbox "strDomain: " & strDomain
strProject = WScript.Arguments(3) '"xyz123"
Msgbox "strProject: " & strProject
strRootNode = WScript.Arguments(4) '"Subject\xyz - Use it!\xyz_abc"
Msgbox "strRootNode: " & strRootNode
Now, when I running the code, it is passing below values properly to vbscript:
QClogin = "abc"
QCpassword = "abc"
sDomain = "xyz"
sProject = "xyz123"
It is having issues with these:
testPathALM = "Subject\xyz - Use it!\xyz_abc"
QCurl = "http://xxx_yyy_zzz/qcbin/"
Now, wierd thing for me is, if I keep a cell empty for "testPathALM" which is having "Subject\xyz - Use it!\xyz_abc" as value, I am getting "QCurl" value properly in vbscript.
But, if I keep value "Subject\xyz - Use it!\xyz_abc" for "testPathALM", then I am getting "-" for strServer which suppose to be "QCurl" value and "Subject\xyz" for "strRootNode" which supposed to be "Subject\xyz - Use it!\xyz_abc".
I am unable to understand what is the issue here.
Thanks a ton in advance.
Safer to quote all of your parameters:
Set wshShell = CreateObject("Wscript.Shell")
Set proc = wshShell.exec("wscript """ & SFilename & """ """ & _
QClogin & """ """ & QCpassword & """ """ & _
sDomain & """ """ & sProject & """ """ & _
testPathALM & """ """ & QCurl & """")
Try a debug.print to make sure it looks as it should...