Using VBA to build SQL with a variable in the From statement RRS feed

  • Question

  • I am developing a database for use by a professional society of engineering type people. I am trying to build, using VPA, SQL that will ask the user which flat file they want to upload, then update a table for that particular flat files name, then append another table with the new flat file data and the data import date.

    I am very new to VBA and am having difficulty getting even little modules to work.

    This is where I am starting at.

    'Declare variables for SQL and for the data source.

    Dim strSQL As String

    Dim strTable as String

    sreTable = "Table_1"

    strSQL = "Select * from "& strTable

    DoCmd.RunSQL strSQL


    Sunday, October 18, 2015 8:41 AM

All replies

  • You don't mention which database you are using.  If it is Access you may want to use that forum:

    Access Forum

    If you are starting from scratch then the best thing is to get a book on Access.

    Sunday, October 18, 2015 2:51 PM
  • It sounds like a lot, all at once, if you don't really know VBA.  Well, I guess this will be a good learning experience.  I think you need to take this one step at a time.  Here's a way to grab a file using the standard Windows File Open/Save dialog box.

    FYI, if you simply load new data into a table with some data already existing in the table, it will simply append the new records.  I think that's what you want.  If not, delete all existing records before importing new records.

    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.

    Tuesday, October 20, 2015 2:07 AM