vivamario
07-28-2014, 12:26 PM
I am trying to import a text comma delimited file to Access. I keep getting the error mentioned above. I am passing the file name with an open file dialog and I'm checking it with a message box so I know the file path is correct. Everything is being done locally on my computer, and I checked with my work's system admin to make sure there weren't any settings affecting my computer/account.
I was originally trying to do this in VB.net and getting a similar 'operation must use an updateable query' error. Both errors seem to be tied to security settings. If I go to security settings for the directory I'm using (C), there is one for the system, users, authenticated users, and the admin; all have full control. Does there need to be a separate group to access files programmatically?
Here is my code:
Private Sub btnText_Click()
'Variables
Dim ofdText As Office.FileDialog
Dim varFile As Variant
Dim intFile As Integer
Dim strFile() As String
Dim intCount As Integer
intFile = 0
Dim i As Integer
'Initiate an Open File Dialog.
Set ofdText = Application.FileDialog(msoFileDialogFilePicker)
With ofdText
'Want to add multiselect in the future.
.AllowMultiSelect = False
.Title = "Select File"
.Filters.Clear
.Filters.Add "Text Files", "*.txt"
.Filters.Add "All Files", "*.*"
If .Show = True Then
intCount = .SelectedItems.Count
ReDim strFile(intCount)
'Loop through all the selected files.
For Each varFile In .SelectedItems
strFile(intFile) = varFile
intFile = intFile + 1
Next
End If
End With
For i = 0 To intCount
MsgBox strFile(i)
'Transfer all text files to Access.
DoCmd.TransferText acImportDelim, , "GroutTable", strFile(i), True
Next
End Sub
I was originally trying to do this in VB.net and getting a similar 'operation must use an updateable query' error. Both errors seem to be tied to security settings. If I go to security settings for the directory I'm using (C), there is one for the system, users, authenticated users, and the admin; all have full control. Does there need to be a separate group to access files programmatically?
Here is my code:
Private Sub btnText_Click()
'Variables
Dim ofdText As Office.FileDialog
Dim varFile As Variant
Dim intFile As Integer
Dim strFile() As String
Dim intCount As Integer
intFile = 0
Dim i As Integer
'Initiate an Open File Dialog.
Set ofdText = Application.FileDialog(msoFileDialogFilePicker)
With ofdText
'Want to add multiselect in the future.
.AllowMultiSelect = False
.Title = "Select File"
.Filters.Clear
.Filters.Add "Text Files", "*.txt"
.Filters.Add "All Files", "*.*"
If .Show = True Then
intCount = .SelectedItems.Count
ReDim strFile(intCount)
'Loop through all the selected files.
For Each varFile In .SelectedItems
strFile(intFile) = varFile
intFile = intFile + 1
Next
End If
End With
For i = 0 To intCount
MsgBox strFile(i)
'Transfer all text files to Access.
DoCmd.TransferText acImportDelim, , "GroutTable", strFile(i), True
Next
End Sub