Hello all,
I have decided to make a dedicated post since I had this as a part of another thread Here.
Basically I need to click on a button and download a file based on URL from a txt box, and place it in folder based on fields. Here is what I have so far:
I'm not getting anything with this.
First part of code (Copy another two files and place them in the same directory) unrelated to this issue:
I have decided to make a dedicated post since I had this as a part of another thread Here.
Basically I need to click on a button and download a file based on URL from a txt box, and place it in folder based on fields. Here is what I have so far:
Code:
Dim objHTTP As Object
Dim FileByte() As Byte
Dim strFile As String
Dim intFile As Integer
Dim URL As String
URL = Forms!frmWIDetail!txtDoc
MsgBox "Your file is " & URL & ""
intFile = Forms!frmWIDetail!txtDoc.Value()
strFile = Mid(URL, InStrRev(URL, "/") + 1)
Set objHTTP = CreateObject("Microsoft.XMLHTTP")
With objHTTP
.Open "GET", URL, False
.Send
If .Status = 200 Then
FileByte = .responseBody
End If
End With
Open strFolder & strSerial & "\" & strFile For Binary Lock Read Write As #intFile
Put #intFile, , FileByte
Close #intFile
Set objHTTP = Nothing
I'm not getting anything with this.
First part of code (Copy another two files and place them in the same directory) unrelated to this issue:
Code:
Public Sub btnGenerate_Click()
Const strParent = "M:\429 QMO\Document Reviews\Document Reviews\"
Dim strSerial As String
Dim strSFolder As String
Dim strFolder As String
Dim fso As Object
Dim FDate As String
Dim Path As String
Dim TRevChk As String
Dim TPriAss As String
Dim TRevChkNew As String
Dim TRevChkOld As String
TRevChk = Forms!frmConfig!fileTRevChk.Value
TPriAss = Forms!frmConfig!fileTPriAss.Value
Path = strParent & Me.fldSerial
FDate = Format(Now, "yyyy")
strSFolder = strParent & FDate & "\"
strFolder = strParent & FDate
strSerial = Me.fldSerial
TRevChkOld = Path & "\" & "DND 4719-E WI Review Checklist.pdf"
TRevChkNew = Path & "\" & "DND 4719-E WI Review Checklist " & "-" & " " & strSerial & ".pdf"
Set fso = VBA.CreateObject("Scripting.FileSystemObject")
On Error Resume Next
If FolderExists(strFolder) = False Then
fso.CreateFolder strFolder
End If
If fso.FolderExists(strSFolder & strSerial) = False Then
fso.CreateFolder strSFolder & strSerial
Call fso.CopyFile(TRevChk, strSFolder & strSerial & "\" & fso.GetBaseName(TRevChk) & " - " & strSerial & "." & fso.GetExtensionName(TRevChk), no)
Call fso.CopyFile(TPriAss, strSFolder & strSerial & "\" & fso.GetBaseName(TPriAss) & " - " & strSerial & "." & fso.GetExtensionName(TPriAss), no)
Else
Call fso.CopyFile(TRevChk, strSFolder & strSerial & "\" & fso.GetBaseName(TRevChk) & " - " & strSerial & "." & fso.GetExtensionName(TRevChk), no)
Call fso.CopyFile(TPriAss, strSFolder & strSerial & "\" & fso.GetBaseName(TPriAss) & " - " & strSerial & "." & fso.GetExtensionName(TPriAss), no)
End If
Me.txtFolder.Value = Path