Can I pass a text box variable into an Access Macro

Posted on 2010-01-07
Last Modified: 2012-05-08
Can I take a varible created by a text box from a form and input it into the TransferSpreadsheet file location in a Macro.  Can I do that in VB is it cannot be done within the macro itself.

Example:  Form Input:.  User puts a file name in a text box. (this is the file he is nameing for a report).  The text box is call fname.
Macro Test: TransferSpreadsheet:
                    Excel 2003
                    Table name: RPT
                    File: C:\Reports\Forms!Input!fname  (Is this part possible)
Question by:swimtech
    LVL 29

    Accepted Solution

    Sure, but you will need to write a VBA macro. This is the syntax for the actual call:

    DoCmd.TransferSpreadsheet acImport, 3, "myTable","C:\Reports\Forms\Input\" & strFileName, True, "A1:G12"


    Author Comment

    Thanks -- Works perfect!   I put htis code under On_Click for my run button.  On the form I give the user a choice to Print to Printer and/or Print to Excel.  Pritn to print was no problem but I wanted the user to be able to name the file something they would remember.  This works great.  Thanks you

    Featured Post

    Live: Real-Time Solutions, Start Here

    Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

    Join & Write a Comment

    Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
    In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
    Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    734 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

    23 Experts available now in Live!

    Get 1:1 Help Now