Add items to LynxGrid not the same type error?
I put the records in a database with access to LynxGrid Type mismatch error, can you see help my code wrong ?
Private Sub Form_Load()
Dim lRow As Integer
'set list columns
With listEntries
.Redraw = False
.AddColumn "ID Code", 50 '0
.AddColumn "Full Name", 150 '1
.AddColumn "Adress", 260 '2
.AddColumn "Telephone", 70 '3
.Redraw = True
.Refresh
End With
strSQL = "SELECT Tabstaff .IDCode, Tabstaff .FullName, Tabstaff .Adress, Tabstaff .Telephone FROM Tabstaff ;"
rsstaff .Open strSQL, DataCustomers, adOpenKeyset, adLockOptimistic
rsstaff .MoveFirst
listEntries.Redraw = False
listEntries.Clear
While Not rsstaff .EOF
With listEntries
lRow = .ItemCount
.AddItem
.CellText(lRow, 0) = rsstaff !IDCode ' This was the type mismatch error, if this line is rem by single quotes, then the next line will error
.CellText(lRow, 1) = rsstaff !Fullname
.CellText(lRow, 2) = rsstaff !Adress
.CellText(lRow, 3) = rsstaff !Telephone
End With
rsstaff .MoveNext
Wend
listEntries.Redraw = True
listEntries.Refresh
rsstaff .Close
End Sub
Re: Add items to LynxGrid not the same type error?
I don't know lynxgrid, but I think the error is this:
The .CellText() property, as the name would suggest, is a text, meaning it is a string data type.
Presumably the IDCode field is numeric and an automatic datatype conversion does not occur.
So try an explicit consversion like
Code:
.CellText(lRow, 0) = CStr(rsstaff!IDCode)
Except, if you have really a BLANK between rssstaff and !IDCode (as your post shows it) then it wouldn't work at all.
Re: Add items to LynxGrid not the same type error?
LynxGrid like as Listview but it've got interface nice than listview. I also tried your way but still the above error
Re: Add items to LynxGrid not the same type error?
You have several spaces in your code that should not be there.
Code:
strSQL = "SELECT Tabstaff .IDCode, Tabstaff .FullName, Tabstaff .Adress, Tabstaff .Telephone FROM Tabstaff ;"
rsstaff .Open strSQL, DataCustomers, adOpenKeyset, adLockOptimistic
rsstaff .MoveFirst
listEntries.Redraw = False
listEntries.Clear
While Not rsstaff .EOF
With listEntries
lRow = .ItemCount
.AddItem
.CellText(lRow, 0) = rsstaff !IDCode ' This was the type mismatch error, if this line is rem by single quotes, then the next line will error
.CellText(lRow, 1) = rsstaff !Fullname
.CellText(lRow, 2) = rsstaff !Adress
.CellText(lRow, 3) = rsstaff !Telephone
You have a space between the tablename and the . for each field selection which is incorrect.
You have a space between each rsstaff and ! which should not be there.
On your select statement there is no need to specify the table name for each field since you are only selecting from one table.
Anyway remove the invalid spaces and give it a try.
Re: Add items to LynxGrid not the same type error?
That's what I hinted, too. But then I thought, if these spaces where really there, an error must have already occured in the rsstaff.open statement. The code wouldn't even get to the line where the type mismatch occurred.
Re: Add items to LynxGrid not the same type error?
this error is not rsstaff.open, you see attach file lynxgrid3a.rar http://www.crocko.com/6F151357267441...lynxgrid3a.rar
Re: Add items to LynxGrid not the same type error?
If you are going to post code please post the actual code. What you have posted has several spaces that should nto be there and the code would not work as a result. If you do not post the actual code then there is no way of knowing what you have doen in the "actual code"
As for the error Type Mismatch means that you are trying to add data that is not the right type for the object. Usually happens when you try to add non numeric data to a numeric field or non date value to a date field.
Check you field types, using the debugger check the data in the var on the line where the error occurrs.