Runtime Error in Access

jason0522

New Member
Joined
May 17, 2011
Messages
3
Hello, Im new to coding VBA and running into a snag. The transferspreadsheet command gives a runtime error 3027. Database or object is read-only. Any ideas?? Thanks in advance


Private Sub Command5_Click()
Dim rs As ADODB.Recordset
Set rs = CurrentProject.Connection.Execute("Store_List")
rs.MoveFirst
Do While Not rs.EOF
Me.Text0.Value = rs.Fields(0)
DoCmd.OpenQuery "KSN", acViewNormal, acEdit DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "KSN", "C:\Spaceman" & Me.Text0.Value & ".csv"
DoCmd.Close

rs.MoveNext
Loop

End Sub
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
1. You don't need the close command as you don't need to open the query to export it.

2. What is Store_List? Is it just a query or table?

Which line is highlighted if you click DEBUG on the error message?
 
Upvote 0
"Store_List" is a query that lists the unique entries of a field in a table. "KSN" is a query that looks at the textbox to filter a table on that field. I want to create a csv file for each unique "KSN" query.

It highlights the line below:
DoCmd.OpenQuery "KSN", acViewNormal, acEdit DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "KSN", "C:\Spaceman" & Me.Text0.Value & ".csv"

Thanks!
 
Upvote 0
Change this:

DoCmd.OpenQuery "KSN", acViewNormal, acEdit DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "KSN", "C:\Spaceman" & Me.Text0.Value & ".csv"

to this

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "KSN", "C:\Spaceman" & Me.Text0.Value & ".csv"

you had two commands bunched together and you can't do that and, like I had said, you do not need to open the query to export it.
 
Upvote 0
I tried that which didn't work but i tried the following with success! I am not sure why this command worked and the other did not. But thanks for all of your help!!

DoCmd.TransferText acExportDelim, , "KSN", "C:\Spaceman\" & Me.Text0.Value & ".csv"
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,287
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top