ACCESS VBA table name as imported text file (1 Viewer)

mansied

Member
Local time
Yesterday, 21:35
Joined
Oct 15, 2020
Messages
99
Hello, I have this code which imports a *.txt file into a table.how can I say change the table to the name of the text file not a fixed name?

Private Sub ImportData_Click()

ImportCompleted = Empty

Dim path As String
path = FilePathText.Value & ""
Dim tblName As String

tblName = "ZM"
If path = "" Then
MsgBox "You need to select a file to import!"
Else
Call Importing.import_ZM(path, tblName)
End If
ImportCompleted = "Import Completed!"

End Sub
 

Gasman

Enthusiastic Amateur
Local time
Today, 02:35
Joined
Sep 21, 2011
Messages
14,238
Parse the Path variable with MID() and RevInstr() and remove the extension and pass that to your function. ?
Of course, the table will need to exist.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 18:35
Joined
Oct 29, 2018
Messages
21,455
Hi. @Gasman probably meant to say InStrRev()...
 

Gasman

Enthusiastic Amateur
Local time
Today, 02:35
Joined
Sep 21, 2011
Messages
14,238
Interesting...

I was not saying I was correct, just that I viewed the posts below and took that to be the correct syntax, which is now obviously incorrect.?

1605206493092.png
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 21:35
Joined
Feb 19, 2002
Messages
43,233
how can I say change the table to the name of the text file not a fixed name?
This sounds like a seriously bad idea. Access is not a spreadsheet. It is a relational database. table and column names should NEVER include data. So you wouldn't have a table named Microsoft or a column named PatHartman.

What are you going to do with this collection of tables? Perhaps, you need ONE table with an additional column that includes the name of the input file the data came from.
 

Users who are viewing this thread

Top Bottom