Solved

Automate ColdFusion Internet Form with VBA from Access

Posted on 2016-11-10
10
16 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_
Comment Utility
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
Comment Utility
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_
Comment Utility
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
 

Author Comment

by:rsburge
Comment Utility
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_
Comment Utility
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 52

Expert Comment

by:_agx_
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you for your help.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Being an active EE Expert means to get a lot of (E)EMail, as you certainly know. If you are using Outlook, I'll show you how to minimize your inbox contents without losing anything – even improve the experience by changing the Subject line to facili…
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

772 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now