Link to home
Create AccountLog in
Avatar of JokoLennono
JokoLennonoFlag for United States of America

asked on

Use textbox value in Form to Change file location in saved import specs (MS Access)

Hi Guys & Gals,

I'm working on an Access project (MS access 2010) & I have an unbound form called "Import Into Account" that I have a file picker/browser to choose the file to import and I want to have VBA update the saved import spec to the file chosen in the file picker/browser on the form, then execute an update query and close the form. I think I have most of the moving pieces good to go, but I don't know how to the file location in the saved import specs to change. Here's the info:

Form Name: Import Into Account
File Path for import csv file: txtImportFileLocation (unbound text box on form)
"filter" for which saved import specs to use: cbImportAccount (unbound dropdown with a list of account names)
button to make it all go: btnImportAccountRunQuery

The saved import specs are named "Chase" and "GTK" & I want it to work like:

Private Sub btnImportAccountRunQuery_Click()
If cbImportAccount = 2 Or cbImportAccount = 3 Then 
ImportSpecifications = "Chase"  
ImportFilelocation = txtImportFileLocation 
DoCmd.OpenQuery "Chase Import Query", acViewNormal, acEdit
Dim UpdateImportedSQL As String
UpdateImportedSQL = "UPDATE [Chase Import] " & _
        "SET Imported = TRUE; "
DoCmd.RunSQL UpdateImportedSQL
DoCmd.Close acForm, "Import Into Account"

Else If If cbImportAccount = 12  Then 
ImportSpecifications = "GTK"  
ImportFilelocation = txtImportFileLocation 
DoCmd.OpenQuery "GTK Import Query", acViewNormal, acEdit
Dim UpdateImportedSQL As String
UpdateImportedSQL = "UPDATE [GTK Import] " & _
        "SET Imported = TRUE; "
DoCmd.RunSQL UpdateImportedSQL
DoCmd.Close acForm, "Import Into Account"
End If
End Sub

Open in new window



Any help would be most appreciated!

Kate
ASKER CERTIFIED SOLUTION
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of JokoLennono

ASKER

DoCmd.TransferText acImportDelim, "YourSpecName", "YourTableName", txtImportLocation

worked perfectly, thank you for your help!
Try my New Style Main Menu (here is a link to the article and sample database):

http://www.helenfeddema.com/Files/accarch212.zip

It allows you to select a path (or several paths) once, to be used throughout the database.  Here is a screen shot of the main menu:

User generated image