Weird error message when saving

Sorry, thought you meant column index. column name is ‘code’

Since ‘code’ is not a keyword in SQLite, the best bet is that rec.FieldName(x) doesn’t return “code” for this column.

Does the value in the listbox cell have “)” or “(” in it?

Eli; now I am totally confused. Are you saying that you can only use specific words to name fields in SQLlite.
Simon; Yes, I checked that one before hitting the forum.

Pasted below is the code that is producing the error

rowcount=lb.listcount

for ctr=0 to rowcount
rec=New DatabaseRecord

for x=0 to columns-1
  
  
  
  rec.Column("[" + rec.FieldName(x) + "]")=lb.Cell(ctr,x)
  db.InsertRecord(table,rec)
  If DB.Error Then
    MsgBox("DB Error: " +DB.ErrorMessage)
  End If
  
  
  
next

next

rowcount=lb.listcount

should be:

rowcount=lb.listcount-1

Chris, it is just a detail, but could you please hit the code icon before you paste, to make it more legible. Look at Simon’s post above for instance. It is far easier to read. Thanks.

Code icon : . Just above text, upper right. Sorry for the missing image in previous post.

 //
 // This code is not 'desk checked' and not tested in Xojo compiler.
 //
 Dim strTmpFieldName As String // Modify the Type as required
 Dim strTmpData As String // Modify the Type as required
 //
 // '-1' below as recommended by 'Simon'
 //
 rowcount = lb.listcount - 1
 For ctr = 0 to rowcount
      rec = New DatabaseRecord
      For x = 0 to columns - 1
           strTmpFieldName = rec.FieldName(x)
           strTmpData = lb.Cell(ctr,x)
           //
           // '[' and ']' below as recommended by 'Eli'
           //
           rec.Column("[" + strTmpFieldName + "]") = strTmpData
           // 
           // Expression simplification above as recommended by 'Deitel and Deitel' 
           //
           db.InsertRecord(table,rec)
           If DB.Error Then
                MsgBox( "DB Error: " +DB.ErrorMessage)
                //
                // Move the 'MsgBox' below to the required point in this code as necessary.
                //
                MsgBox( "strTmpFieldName = >" + strTmpFieldName + "<" + EndOfLine _
                    + "strTmpData = >" + strTmpData + "<" + EndOfLine _
                    + "ctr = " + Trim(Str(ctr)) + EndOfLine _
                    + "x = " + Trim(Str(x)) )
           End If
      Next
 Next

This indicates that rec.FieldName(x) is not returning the correct value. Have you examined it? What is it returning? And you appear to be correlating the columns of a listbox with the fields of a recordset? I’m not sure that’s such a good idea.

As is probably evident by my sloppy coding in the above paste, I am a former VB coder, that got away for years with having most of the hard work done for me by the UI and tolerant compiler. My thanks to all who provided input on what should have been a simple bit of coding that I managed to complicate with faulty syntax.