Solved

Automate ColdFusion Internet Form with VBA from Access

Posted on 2016-11-10
10
56 Views
Last Modified: 2016-11-14
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
Comment
Question by:rsburge
  • 6
  • 4
10 Comments
 
LVL 52

Expert Comment

by:_agx_
ID: 41883258
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
 

Author Comment

by:rsburge
ID: 41883282
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
 
LVL 52

Expert Comment

by:_agx_
ID: 41883896
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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:rsburge
ID: 41883907
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
 
LVL 52

Expert Comment

by:_agx_
ID: 41883926
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
 
LVL 52

Expert Comment

by:_agx_
ID: 41883937
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
 
LVL 52

Assisted Solution

by:_agx_
_agx_ earned 500 total points
ID: 41883948
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
 

Author Comment

by:rsburge
ID: 41883993
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
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 41884030
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
 

Author Comment

by:rsburge
ID: 41884171
Thank you for your help.
0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question