[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 107
  • Last Modified:

Automate ColdFusion Internet Form with VBA from Access

Hello Experts -

My head developer/VP of our division created a basic ColdFusion input form so I could upload a file.  He is not familiar with VBA and I am not familiar with ColdFusion so we can't figure out how to automate uploading this file using VBA from Access.

Neither of us can figure out how to pass the file path into the File Contents field.  It appears that you have to click on the Browse button and browse to the file.  I can't even figure out how to click on the Browse button.

The source code for the page, http://www.loanxwebservice.com/upl_suntrust_ratesheet.cfm, is below.   I am still a beginner with VBA, so some example code would be very helpful.

<script type="text/javascript" src="/CFIDE/scripts/cfform.js"></script>
<script type="text/javascript" src="/CFIDE/scripts/masks.js"></script>
<script type="text/javascript"> 
<!--
    _CF_checkCFForm_1 = function(_CF_this)
    {
       //reset on submit
        _CF_error_exists = false;
        _CF_error_messages = new Array();
        _CF_error_fields = new Object();
        _CF_FirstErrorField = null;

 
        //display error messages and return success
        if( _CF_error_exists )
        {
            if( _CF_error_messages.length > 0 )
            {
                // show alert() message
                _CF_onErrorAlert(_CF_error_messages);
                // set focus to first form error, if the field supports js focus().
                if( _CF_this[_CF_FirstErrorField].type == "text" )
                { _CF_this[_CF_FirstErrorField].focus(); }

            }
            return false;
        }else {
            return true;
        }
    }
//-->
</script>

 
 
 
 
        <h3>&nbsp;Upload Suntrust - Ratesheet</h3>
<form name="CFForm_1" id="CFForm_1" action="act_suntrust_update_ratesheet.cfm" method="POST" enctype="multipart/form-data" onsubmit="return _CF_checkCFForm_1(this)">
<table width="100%" border="0" cellspacing="2" cellpadding="2" align="center">
  <tr>
    <td colspan="2">
      &nbsp;
</td>
  </tr>
  <tr>
    <td colspan="2" align="center">
      <P><b>Upload Ratesheet</b>
</td>
  </tr>
  <tr>
    <td align="right">
<P><b>CSV/XLS file:</b>
</td>
    <td align="left">
<input type="file" name="FileContents" size="50">
</td>
  </tr>

  <tr>
    <td colspan="2">
      &nbsp;
</td>
  </tr>
  <tr>
    <td colspan="2" align="center">
  <button class="btn btn-primary" type="submit" name="Operation" value="Update">
  Update <span class="glyphicon glyphicon-chevron-right"></span>
  </button>
      &nbsp;
  <input type="submit" name="Operation" value="Cancel" class="btn btn-default">
</form>

</td>
  </tr>
  <tr>
    <td colspan="2">
      &nbsp;
</td>
  </tr>
</table>

Open in new window

0
rsburge
Asked:
rsburge
  • 6
  • 4
2 Solutions
 
_agx_Commented:
how to pass the file path into the File Contents field

You can't. Not without some sort of signed control. For security reasons, browsers are prohibited from modifying the value of file fields with JS by default. Otherwise, malicious sites could just copy files off a user's drive without consent.

EDIT: That said, I'm a little confused about how/if VBA fits in here... Can you elaborate on what you mean by "automate uploading this file ..."?
0
 
rsburgeAuthor Commented:
The purpose of this CF form is to upload a file that is then converted to something else and stored on our backend server.

I have an access database application that uses VBA to reach out to another website to pull the file and save the file on the hard drive.  The next step of this process would be uploading that file into our system using this online form.
0
 
_agx_Commented:
The next step of this process would be uploading that file

If by "automate" you mean programmatically populate the file field, and submit the form it can't be done with plain html/JS.  You'd need to use some sort of signed control, like activeX, etc... to achieve that.

application that uses VBA to reach out to another website to pull the file and save the file on the hard drive

However, it's simpler to skip the VBA and client side form. Just use CF to retrieve the remote file using CFHTTP and save it directly to the server.  Something like

<cfhttp method = "get"
    url = "http://somesite.com/path/To/someFile.ext"
    getAsBinary="yes"
    path="c:/path/on/server/" 
    file="someFile.ext" />

Open in new window

0
New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

 
rsburgeAuthor Commented:
Unfortunately, having ColdFusion reach out directly to the site for the file is not an option at this time.  The site requires multi-level security login and navigating through multiple pages, and finding the correct file, and clicking on download, then the file opens on in excel and you have to save it.  I have all of this happening through the VBA code.

If I understand you correctly, there is no way to programmatically click on that Browse button, the process will always be manual... unless the developer wants to put in some sort of activeX control in front of the CF form?
0
 
_agx_Commented:
Correct.  This restriction has nothing to do with CF.  It is a browser security feature and the behavior is by design. Client side code, ie javascript, isn't allowed to modify file fields programmatically without user consent.  The only way to do this is to use a signed or authorized control, ie applet, flash, activeX, etc...  For example: https://social.msdn.microsoft.com/Forums/en-US/f3c0097c-d732-409d-87d4-59b3875b45b4/populate-file-type-input-field-with-text-field-value?forum=Vsexpressvb
0
 
_agx_Commented:
I have all of this happening through the VBA code.

Hm.... what about doing an http post with VBA? In other words, skip the html form and upload the file directly to CF.  I'm relatively sure vba can do an http post operation. Unfortunately, I haven't used vba in a really long time, so I can't offer specific advice on that code.
0
 
_agx_Commented:
I took a brief look in the archives for uploading and vba. Maybe this will help?

https://www.experts-exchange.com/questions/26638368/multipart-upload-from-excel-VBA.html
0
 
rsburgeAuthor Commented:
Thank you both.

I have looked at the question you referenced and it is all looking a bit complex to me.  

It appears to me that I should be able to use just the first sum, ExportToServer, since I already have the file saved and ready to upload, that I would just need to define my variables properly instead of calling other subs to create the file.  

Does this sound right to you?
0
 
_agx_Commented:
In theory, but ... VBA isn't really my area.  I can only comment on the CF/html/JS side of things.  If you need a VBA specific answer, I'd post a separate question about doing a multipart/form-data post, ie uploading a file with VBA.  It's entirely possible there are newer/better ways to do this.   Sorry I couldn't be of more help on the VBA side.
0
 
rsburgeAuthor Commented:
Thank you for your help.
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now