I have used basically the same code for years to retrieve records based on the row the user doubleclicks.
The PopulateListBox and the DoubleClick events are shown below.
This problem has just started and I can’t figure it out. I have duplicated the problem on the same row regardless of how the records are sorted. The problem occurs when the 21st or following rows are clicked.
when it works ok, i contains the row number. Where the error occurs, i = -1
The PopulateListBox method:
[code]
dim i As Integer
dim j As Integer // J is just to make counting the ROW easy
dim sCaptureDate As String
rsImages.MoveFirst
lbImages.deleteAllRows
j = 1
i = 0
while not rsImages.eof
sCaptureDate = rsImages.Field( "CaptureTime" ).StringValue
sCaptureDate = Left(sCaptureDate, 10)
lbImages.addRow "1"
lbImages.cell( i, 0 ) = rsImages.Field("pkRecID").StringValue
lbImages.cell( i, 1 ) = rsImages.Field( "BaseName" ).StringValue
lbImages.cell( i, 2 ) = rsImages.Field( "Title" ).StringValue
lbImages.cell( i, 3 ) = rsImages.Field( "Path" ).StringValue
lbImages.cell( i, 4 ) = sCaptureDate
lbImages.cell( i, 5 ) = str(j)
i = i + 1
j = j + 1
rsImages.MoveNext
wend
iCurrentRowCount = rsImages.RecordCount
tfRowCount.Text = str(iCurrentRowCount)
rsImages.MoveFirst
Return[/code]
The DoubleClick event of the ListBox:
dim iRow As Integer
dim sImageID As String
dim sSQL As String
iRow = Me.RowFromXY(System.MouseX - Me.Left - Self.Left, System.MouseY - Me.Top - Self.Top)
sImageID = me.cell( iRow, 0 )
sSQL = "SELECT * FROM ImageMaster WHERE pkRecID = " + sImageID // this is the problem
rsRecall = dbSQL.SQLSelect(sSQL)
if dbSQL.Error then
MsgBox(dbSQL.ErrorMessage)
Quit
end if
tpPanels.Value = 1
PopulateDataEntryFields
cPreview.Backdrop = nil
return
The problem occurs when “rsRecall = dbSQLSQLSelect(sSQL)” executes and it is a sql error that says Syntax error near “11” which is the pkRecID field
When the problem happens, sSQL was apparently corrupted as it has a lot of extra digits. See below
The contents of sSQL when the error does not occur:
SELECT * FROM ImageMaster WHERE pkRecID = 24
The contents of sSQL when the error DOES occur:
SELECT * FROM ImageMaster WHERE pkRecID = 1
11
2
12
3
13
4
14
5
15
6
16
20
10
22
23
24
7
17
8
18
9
19
21