David McAfee
DMcAfee at haascnc.com
Tue Jul 22 16:13:46 CDT 2003
I have an A2K ADP FE and a SQL 2K BE.
I have created both DAO and ADO recordsets to read the data from a "temp db"
but I cannot figure out how to assign the listbox's rowsource to that of the
recordset. I was looking at using a callback function to fill the listbox,
but that's causing my hair to fall out :(
I have the following recordset (can switch to ADO if it will be easier),
Where on earth does this go in conjunction with the call back? To I open the
recordset before initializing the callback or during? I believe that I need
to place the open recordset statement inside the acLBInitialize Case then
get the tsTmp.recordcount into a variable
Dim Tmpdb As DAO.Database, rsTmp As DAO.Recordset, intrsTmpCount AS integer
Set Tmpdb = OpenDatabase(Application.CurrentProject.Path &
"\TempRRentry.mdb")
Set rsTmp = Tmpdb.OpenRecordset("SELECT * from ""RRentry"" WHERE (ADE <>
3")
If Not rsTmp.BOF And Not rsTmp.EOF Then
rsTmp.MoveLast
rsTmp.MoveFirst
intrsTmpCount= rsTmp.RecordCount
End If
rsTmp.Close
Set rsTmp = Nothing
Tmpdb.Close
Set Tmpdb = Nothing
Sample Callback code:
Private Function Fill_lstLI(ctrl As Control, id As Variant, row As Variant,
col As Variant, code As Variant) As Variant
Select Case code
Case acLBInitialize
' Any necessary initialization code goes here.
' For example: determine number or rows and number
' of columns, save these values in the intRows and
' intColumns variables, and re-dimension the Static array
' varDisplayData().
Dim Tmpdb As DAO.Database, rsTmp As DAO.Recordset, intrsTmpCount
As Integer
Set Tmpdb = OpenDatabase(Application.CurrentProject.Path &
"\TempRRentry.mdb") 'MDB Name was chosen in Function CreateDB
Set rsTmp = Tmpdb.OpenRecordset("SELECT * from ""RRentry""
WHERE (ADE <> 3")
If Not rsTmp.BOF And Not rsTmp.EOF Then
rsTmp.MoveLast
rsTmp.MoveFirst
intrsTmpCount = rsTmp.RecordCount
End If
rsTmp.Close
Set rsTmp = Nothing
Tmpdb.Close
Set Tmpdb = Nothing
Fill_lstLI = 1
Case acLBOpen ' Generate unique ID for control.
Fill_lstLI = 1
Case acLBGetRowCount ' Get number of rows.
Fill_lstLI = varRecords
Case acLBGetColumnCount ' Get number of rows.
Fill_lstLI = Me.lstLineItems.ColumnCount '13
Case acLBGetColumnWidth ' Column width (In twips).
' -1 forces use of default width.
Fill_lstLI = -1
Case acLBGetValue ' Get data.
Fill_lstLI = varRecords(row)
Case acLBGetFormat
Fill_lstLI = -1
Case acLBEnd
ReDim varRecords(1 To 1)
'varRecordsCount = -1
End Select
End Function
The recordset pulls back 13 columns which are in the same order as they are
displayed in the listbox from left to right. Is there anyone out there who
has dealt with these beasts that has a bit of time to help me get this
through my thick skull?
TIA
David McAfee