From: LA Lawyer on
I am able to access my Access 2007 data, but the commands to add the item in
the control fails; I have moved the with/end with commands to different
places, but none works. Obviously, I am running this when the form
initializes. Here is my code with the bad code noted:

BAD---With CaseNames
Dim cn As ADODB.Connection
Dim Rs As ADODB.Recordset
Dim SqlStr As String
SqlStr = "SELECT * FROM " & TableName & " WHERE ([ActiveCase] = True) ORDER
BY CaseName"
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & _
DBFullName & ";"
Set Rs = New ADODB.Recordset

With Rs
.Open SqlStr, cn, adOpenStatic, adLockOptimistic, adCmdText
Dim rcd As Record
Do Until Rs.EOF
.AddItem Rs!casename
Rs.MoveNext
Loop
End With
End With
Rs.Close
Set Rs = Nothing
cn.Close
Set cn = Nothing
BAD ----End With


From: Doug Robbins - Word MVP on
See http://gregmaxey.mvps.org/Populate_UserForm_ListBox.htm

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com

"LA Lawyer" <hkapp(a)kapplaw.com> wrote in message
news:uh8KZz$2KHA.4716(a)TK2MSFTNGP06.phx.gbl...
> I am able to access my Access 2007 data, but the commands to add the item
> in the control fails; I have moved the with/end with commands to different
> places, but none works. Obviously, I am running this when the form
> initializes. Here is my code with the bad code noted:
>
> BAD---With CaseNames
> Dim cn As ADODB.Connection
> Dim Rs As ADODB.Recordset
> Dim SqlStr As String
> SqlStr = "SELECT * FROM " & TableName & " WHERE ([ActiveCase] = True)
> ORDER BY CaseName"
> Set cn = New ADODB.Connection
> cn.Open "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & _
> DBFullName & ";"
> Set Rs = New ADODB.Recordset
>
> With Rs
> .Open SqlStr, cn, adOpenStatic, adLockOptimistic, adCmdText
> Dim rcd As Record
> Do Until Rs.EOF
> .AddItem Rs!casename
> Rs.MoveNext
> Loop
> End With
> End With
> Rs.Close
> Set Rs = Nothing
> cn.Close
> Set cn = Nothing
> BAD ----End With
>
From: LA Lawyer on
Thank you!

"Doug Robbins - Word MVP" <dkr(a)REMOVECAPSmvps.org> wrote in message
news:672B618D-D2ED-4250-A1CE-B239C3E999CF(a)microsoft.com...
> See http://gregmaxey.mvps.org/Populate_UserForm_ListBox.htm
>
> --
> Hope this helps.
>
> Please reply to the newsgroup unless you wish to avail yourself of my
> services on a paid consulting basis.
>
> Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
>
> "LA Lawyer" <hkapp(a)kapplaw.com> wrote in message
> news:uh8KZz$2KHA.4716(a)TK2MSFTNGP06.phx.gbl...
>> I am able to access my Access 2007 data, but the commands to add the item
>> in the control fails; I have moved the with/end with commands to
>> different places, but none works. Obviously, I am running this when the
>> form initializes. Here is my code with the bad code noted:
>>
>> BAD---With CaseNames
>> Dim cn As ADODB.Connection
>> Dim Rs As ADODB.Recordset
>> Dim SqlStr As String
>> SqlStr = "SELECT * FROM " & TableName & " WHERE ([ActiveCase] = True)
>> ORDER BY CaseName"
>> Set cn = New ADODB.Connection
>> cn.Open "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & _
>> DBFullName & ";"
>> Set Rs = New ADODB.Recordset
>>
>> With Rs
>> .Open SqlStr, cn, adOpenStatic, adLockOptimistic, adCmdText
>> Dim rcd As Record
>> Do Until Rs.EOF
>> .AddItem Rs!casename
>> Rs.MoveNext
>> Loop
>> End With
>> End With
>> Rs.Close
>> Set Rs = Nothing
>> cn.Close
>> Set cn = Nothing
>> BAD ----End With
>>