[AccessD] Populate Unbound Listbox from SQL Server Recordset Help.

Darryl Collins Darryl.Collins at coles.com.au
Mon Aug 18 19:34:59 CDT 2008


Hi all,

I think I am getting my brain bogged down in all this and fouling something simple up.  In short I want to use an ADO connection to return a RecordSet to populate an unbound listbox on an Access Form.  And I cannot seem to get it to work.  I do this all the time in Excel - that is copy a recordset to a worksheet.  Can you populate an unbound listbox using the same concept?  Everything seems to work except the 'populate RowSource in listbox with recordset data' bit. hmmmm.

'''========== IN EXCEL I USE THIS =======================

Option Explicit
Option Private Module

Sub DL_MECTable()

Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim strSQL As String

<non relevant code snipped>

Set cnn = New ADODB.Connection
Set rst = New ADODB.Recordset
Set gobjXL = Application.ThisWorkbook

strSQL = ""
strSQL = strSQL & "SELECT BaselineSource, BaselineSourceID FROM ITFCT_tblBaselineSource"
strSQL = strSQL & " ORDER BY SortSequence;"

With rst
    .Source = strSQL
    .ActiveConnection = DbADOConStr
    .CursorType = adOpenForwardOnly
    .LockType = adLockReadOnly
    .CursorLocation = adUseClient
    .Open Options:=adCmdText
    '.Open Options:=adCmdStoredProc
End With

Sheet2.Range("D13").CopyFromRecordset rst

<non relevant code snipped>

End Sub

'=====================================================


in Access I was using the same ADO connection code (which works fine) and then:

[Forms]![ITFCT_frmStartHere].lstbxAPLIDxUser.RowSource = rst

but this goes into error.  I think I am fouling something up there.

Anyone got any pointers here?

Regards

Darryl.


This email and any attachments may contain privileged and confidential information
and are intended for the named addressee only. If you have received this e-mail in
error, please notify the sender and delete this e-mail immediately. Any
confidentiality, privilege or copyright is not waived or lost because this e-mail
has been sent to you in error. It is your responsibility to check this e-mail and
any attachments for viruses.  No warranty is made that this material is free from
computer virus or any other defect or error.  Any loss/damage incurred by using this
material is not the sender's responsibility.  The sender's entire liability will be
limited to resupplying the material.





More information about the AccessD mailing list