DatabaseState is ReadOnly
Posted 21 September 2001 - 03:18
Posted 21 September 2001 - 18:44
Posted 21 September 2001 - 19:55
I have a ComboBox whose property is set to 'Location', and I'm trying to add items to the ComboBox at run-time. I can read the values out of the ComboBox, I just can't add any. Here's a sample of my code:
Dim oDatabase
Dim oView
Dim oRecord
Dim sSQL
Set oDatabase = Session.Database
sSQL = "SELECT * FROM ComboBox WHERE Property = 'Location'"
Set oView = oDatabase.OpenView(sSQL)
oView.Execute
Set oRecord = oView.Fetch
MsgBox oRecord.StringData(4)
sSQL = "INSERT INTO ComboBox (Property, Order, Value, Text) VALUES ('Location', 1123, '5', 'TestText' TEMPORARY)"
On Error Resume Next
Set oView = oDatabase.OpenView(sSQL)
If Err.Number <> 0 Then
MsgBox "Error " & Err.Number & " : " & Err.Description
On Error Goto 0
End If
The first MsgBox does display the text of the existing item in the ComboBox (which was entered at design-time), but the second call to the OpenView method of the Database object throws an error. The description of the trapped error is "OpenView,sql", which leads me to believe the SQL is improperly formatted, but I can't seem to find anything wrong with it.
Posted 24 September 2001 - 12:57
Posted 24 September 2001 - 15:07
sSQL = "INSERT INTO ComboBox (Property, Order, Value, Text) VALUES ('Location', 1123, '5', 'TestText') TEMPORARY"
I even tried making a parameterized query out of it, and that doesn't work either. I always get the 'OpenView,slq' error.
sSQL = "INSERT INTO ComboBox (Order, Value, Text, Property) VALUES (?, ?, ?, 'Location') TEMPORARY"
Is there some fundamental error that I'm making? Or is this code theoretically sound?
(Edited by dkingston at 9:13 am on Sep. 24, 2001)
Posted 25 September 2001 - 03:14
Quote |
To escape table names and column names that clash with SQL keywords, enclose the name between two grave accent marks `` (ASCII value 96). |
The offending word, in this case, is Order. From now on, I'll wrap all table and field names in grave accents just to reduce the chance of this tripping me up again. The final functioning SQL is this:
sSQL = "INSERT INTO `ComboBox` (`Property`, `Order`, `Value`, `Text`) VALUES ('Location', 1123, '5', 'TestText') TEMPORARY"