Improve company productivity with a Business Account.Sign Up

x
?
Solved

Automate ColdFusion Internet Form with VBA from Access

Posted on 2016-11-10
10
Medium Priority
?
134 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 53

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 53

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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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 53

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 53

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 53

Assisted Solution

by:_agx_
_agx_ earned 2000 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 53

Accepted Solution

by:
_agx_ earned 2000 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

606 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