我正在尝试将表格从Excel导出到Access数据库中的表格,但我一直收到错误"数据库或对象是只读的#34;。这是qestion中的代码。
dbWB = Application.ActiveWorkbook.FullName
dbWS = Application.ActiveSheet.Name
dsh = "[" & dbWS & "$]"
Set DB = CreateObject("ADODB.Connection")
dbPath = "\\Corpaa.aa.com\CampusHome\IOCADHome02\758673\Projects\Global Analysis Tool\MX Analysis DB\Global Line MX Hub Review DB.accdb"
scn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & dbPath
DB.Open scn
DB.Execute "DELETE * FROM tblNewSchedule;"
SQLInsert = "INSERT INTO tblNewSchedule "
SQLSelect = "SELECT * "
SQLFrom = "FROM [Excel 8.0; HDR=YES; DATABASE= " & dbWB & "]." & dsh & " "
strQry = SQLInsert & SQLSelect & SQLFrom & ";"
DB.Execute strQry
DB.Close
DELETE
qry执行得很好,没有任何错误。问题是strQry
执行。我相信它正在重申WB是只读的,但我正在运行WB的代码。我正在运行Office 2010.感谢您的帮助。
答案 0 :(得分:0)
所以,在继续搜索之后,我发现了一种完美的不同方法。我在here
上找到了它这是我的新工作代码。谢谢你的帮助。
import Foundation
import CoreLocation
class PositionController: CLLocationManager, CLLocationManagerDelegate {
let locationManager: CLLocationManager
var userPosition = Position(longitude: 0,latitude: 0)
override init() {
self.locationManager = CLLocationManager()
print("---------------Init---------------------------")
}
func setPositionViaLocationData(){
locationManager.delegate = self
locationManager.requestWhenInUseAuthorization()
locationManager.desiredAccuracy = kCLLocationAccuracyKilometer
locationManager.requestLocation()
}
func setPosition(longitude: Double, latitude: Double){
userPosition.longitude = longitude
userPosition.latitude = latitude
}
func getPosition() -> (userLongitude: Double, userLatitude: Double){
return (userPosition.longitude, userPosition.latitude)
}
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
print(error)
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let locValue:CLLocationCoordinate2D = manager.location!.coordinate
print("locations = \(locValue.latitude) \(locValue.longitude)")
userPosition.latitude = locValue.latitude
userPosition.longitude = locValue.longitude
}
}