PDA

View Full Version : TransferText Runtime Error 3011



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

jonh
07-28-2014, 02:54 PM
So are you using a query or not? Queries are usually readonly if you have grouping turned on or are linking fields on non primary keys.

vivamario
07-28-2014, 03:32 PM
So are you using a query or not? Queries are usually readonly if you have grouping turned on or are linking fields on non primary keys.
I tried running a query from vb.net and it didn't work so I tried the code above. I don't really know how TransferText works. I'm guessing it uses the wizard. I prefer what I have above but I'll use vb.net if that's an easier fix.

jonh
07-28-2014, 03:50 PM
All I can see is grouttable which means nothing.
As said above, queries can be read only. If you open the the query manually and and can't change it, you won't be able to change it through code either.

vivamario
07-28-2014, 04:19 PM
All I can see is grouttable which means nothing.
As said above, queries can be read only. If you open the the query manually and and can't change it, you won't be able to change it through code either.

I can import the table with the Access wizard and it works fine. I can perform other functions through VBA or manually no problem. There are no restrictions on the file. It's brand new, I made it myself locally.

jonh
07-29-2014, 03:45 PM
I know there is nothing wrong with the file.
If vb.net gives the same error as access it's an issue with access.
But you still haven't told me what grouttable is.

You can save the file specification generated by the import wizard and use it for future imports. I'm not at a pc so you'll need to refer to the help file for specifics.

vivamario
07-29-2014, 11:32 PM
I know there is nothing wrong with the file.
If vb.net gives the same error as access it's an issue with access.
But you still haven't told me what grouttable is.

You can save the file specification generated by the import wizard and use it for future imports. I'm not at a pc so you'll need to refer to the help file for specifics.

GroutTable is the table already set up in Access. I will look into how to save the spec file and see if that helps. Thanks.