Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access thread: Populate (AddItem) in ComboBox


Message #1 by "George Oro" <george@c...> on Tue, 22 Oct 2002 17:50:04 +0400
Thanks Bob for your idea and tips on my below post "Binding Fields".

By the way, how can I populate or add item on my combo box using code?
On my below post, I just add one ComboBox field "Job Title" and I have a table on my Access2K Back-end called d57TblJobTitle with
the following fields d57JobTitleID & d57JobTitle.

Any help is highly appreciated.
TIA
George ;D

-----Original Message-----
From: Bob Bedell [mailto:bobbedell15@m...]
Sent: Monday, October 21, 2002 9:15 PM
To: Access
Subject: [access] Re: Binding Fields


Hi George,

That's how its done. Why are you using WithEvents in you declaration?
You don't need it in this module. Only recommendation would be: in order
to prevent your cursor from falling off the beginning or end of your
recordset and producing weird error messages, have your navigation
buttons check for the recordsets BOF and EOF properties. The following
code also gives the user some halpful visual cues by enabling and
disabling the appropriate navigation buttons.

Private Sub cmdPrev_Click()

    rsContacts.MovePrevious
    txtContactsID.SetFocus
    rsContacts.MovePrevious
    If rsContacts.BOF Then
        cmdPrev.Enabled = False
    Else
        cmdPrev.Enabled = True
    End If
    cmdNext.Enabled = True
    rsContacts.MoveNext

    BindAllFields

End Sub

Private Sub cmdNext_Click()
    rsContacts.MoveNext
    txtContactsID.SetFocus
    rsContacts.MoveNext
    If rsContacts.EOF Then
        cmdNext.Enabled = False
    Else
        cmdNext.Enabled = True
    End If
    rsContacts.MovePrevious
    cmdPrev.Enabled = True

    BindAllFields
End Sub

Best,

Bob

>From: "George Oro" <george@c...>
>Reply-To: "Access" <access@p...>
>To: "Access" <access@p...>
>Subject: [access] Binding Fields
>Date: Mon, 21 Oct 2002 18:16:59 +0400
>
>Hi Guys,
>
>I just started connecting my database using ADODB coding, at present, I
>just have 3 textbox fields and two cmdButton for test with
>the following code:
>QUESTION:
>1) Is my connection OK? otherwise what is the best?
>2) Is there any easiest way to bind my fields accordingly?
>
>Any help and idea is highly appreciated.
>Cheers,
>George
>
>MY CODE
>----------
>Option Compare Database
>Option Explicit
>Dim WithEvents rsContacts As ADODB.Recordset
>----------
>
>Private Sub Form_Open(Cancel As Integer)
>     'Database Connection
>     Dim cn As ADODB.Connection
>     Dim strCn As String
>
>     Set cn = New ADODB.Connection
>     strCn = "Provider=Microsoft.Jet.OLEDB.4.0;Data
>Source=C:\Database\MyVBapp\Communicator ComData.mdb;Persist Security
>Info=False"
>     cn.Open strCn
>
>     'Recordset Connection
>     'Dim rsContacts As ADODB.Recordset
>     Dim strRSContacts As String
>
>     Set rsContacts = New ADODB.Recordset
>     strRSContacts = "SELECT * FROM m01TblContacts"
>     rsContacts.Open strRSContacts, cn, adOpenStatic, adLockOptimistic
>
>     BindAllFields
>
>End Sub
>----------------
>Private Sub BindAllFields()
>     With Me
>         .txtContactsID = rsContacts("m01ContactsID")
>         .txtFirstName = rsContacts("m01FirstName")
>         .txtLastName = rsContacts("m01LastName")
>     End With
>End Sub
>---------------
>Private Sub cmdNext_Click()
>On Error GoTo Err_cmdNext_Click
>
>
>     rsContacts.MoveNext
>     BindAllFields
>
>Exit_cmdNext_Click:
>     Exit Sub
>
>Err_cmdNext_Click:
>     MsgBox Err.Description
>     Resume Exit_cmdNext_Click
>
>End Sub
>----------------
>Private Sub cmdPrev_Click()
>On Error GoTo Err_cmdPrev_Click
>
>
>     rsContacts.MovePrevious
>     BindAllFields
>
>Exit_cmdPrev_Click:
>     Exit Sub
>
>Err_cmdPrev_Click:
>     MsgBox Err.Description
>     Resume Exit_cmdPrev_Click
>
>End Sub
>
>


_________________________________________________________________
Choose an Internet access plan right for you -- try MSN!
http://resourcecenter.msn.com/access/plans/default.asp



Message #2 by "John Pace" <jpace@h...> on Tue, 22 Oct 2002 09:01:50 -0500
George, 

Do the following (I am assuming you are using a recordset call
rstJobTitle).
If you want to add all the records in the recordset to the combo box do
the following:

With rstJobTitle

	.MoveFirst

	Do Until .EOF

		ComboBox.AddItem !d57JobTitleID & " - " & !d57JobTitle
		
		.MoveNext

	Loop

End With

Hope that helps,

John

-----Original Message-----
From: George Oro [mailto:george@c...] 
Sent: Tuesday, October 22, 2002 7:50 AM
To: Access
Subject: [access] Populate (AddItem) in ComboBox

Thanks Bob for your idea and tips on my below post "Binding Fields".

By the way, how can I populate or add item on my combo box using code?
On my below post, I just add one ComboBox field "Job Title" and I have a
table on my Access2K Back-end called d57TblJobTitle with
the following fields d57JobTitleID & d57JobTitle.

Any help is highly appreciated.
TIA
George ;D

-----Original Message-----
From: Bob Bedell [mailto:bobbedell15@m...]
Sent: Monday, October 21, 2002 9:15 PM
To: Access
Subject: [access] Re: Binding Fields


Hi George,

That's how its done. Why are you using WithEvents in you declaration?
You don't need it in this module. Only recommendation would be: in order
to prevent your cursor from falling off the beginning or end of your
recordset and producing weird error messages, have your navigation
buttons check for the recordsets BOF and EOF properties. The following
code also gives the user some halpful visual cues by enabling and
disabling the appropriate navigation buttons.

Private Sub cmdPrev_Click()

    rsContacts.MovePrevious
    txtContactsID.SetFocus
    rsContacts.MovePrevious
    If rsContacts.BOF Then
        cmdPrev.Enabled = False
    Else
        cmdPrev.Enabled = True
    End If
    cmdNext.Enabled = True
    rsContacts.MoveNext

    BindAllFields

End Sub

Private Sub cmdNext_Click()
    rsContacts.MoveNext
    txtContactsID.SetFocus
    rsContacts.MoveNext
    If rsContacts.EOF Then
        cmdNext.Enabled = False
    Else
        cmdNext.Enabled = True
    End If
    rsContacts.MovePrevious
    cmdPrev.Enabled = True

    BindAllFields
End Sub

Best,

Bob

>From: "George Oro" <george@c...>
>Reply-To: "Access" <access@p...>
>To: "Access" <access@p...>
>Subject: [access] Binding Fields
>Date: Mon, 21 Oct 2002 18:16:59 +0400
>
>Hi Guys,
>
>I just started connecting my database using ADODB coding, at present, I
>just have 3 textbox fields and two cmdButton for test with
>the following code:
>QUESTION:
>1) Is my connection OK? otherwise what is the best?
>2) Is there any easiest way to bind my fields accordingly?
>
>Any help and idea is highly appreciated.
>Cheers,
>George
>
>MY CODE
>----------
>Option Compare Database
>Option Explicit
>Dim WithEvents rsContacts As ADODB.Recordset
>----------
>
>Private Sub Form_Open(Cancel As Integer)
>     'Database Connection
>     Dim cn As ADODB.Connection
>     Dim strCn As String
>
>     Set cn = New ADODB.Connection
>     strCn = "Provider=Microsoft.Jet.OLEDB.4.0;Data
>Source=C:\Database\MyVBapp\Communicator ComData.mdb;Persist Security
>Info=False"
>     cn.Open strCn
>
>     'Recordset Connection
>     'Dim rsContacts As ADODB.Recordset
>     Dim strRSContacts As String
>
>     Set rsContacts = New ADODB.Recordset
>     strRSContacts = "SELECT * FROM m01TblContacts"
>     rsContacts.Open strRSContacts, cn, adOpenStatic, adLockOptimistic
>
>     BindAllFields
>
>End Sub
>----------------
>Private Sub BindAllFields()
>     With Me
>         .txtContactsID = rsContacts("m01ContactsID")
>         .txtFirstName = rsContacts("m01FirstName")
>         .txtLastName = rsContacts("m01LastName")
>     End With
>End Sub
>---------------
>Private Sub cmdNext_Click()
>On Error GoTo Err_cmdNext_Click
>
>
>     rsContacts.MoveNext
>     BindAllFields
>
>Exit_cmdNext_Click:
>     Exit Sub
>
>Err_cmdNext_Click:
>     MsgBox Err.Description
>     Resume Exit_cmdNext_Click
>
>End Sub
>----------------
>Private Sub cmdPrev_Click()
>On Error GoTo Err_cmdPrev_Click
>
>
>     rsContacts.MovePrevious
>     BindAllFields
>
>Exit_cmdPrev_Click:
>     Exit Sub
>
>Err_cmdPrev_Click:
>     MsgBox Err.Description
>     Resume Exit_cmdPrev_Click
>
>End Sub
>
>


_________________________________________________________________
Choose an Internet access plan right for you -- try MSN!
http://resourcecenter.msn.com/access/plans/default.asp





Message #3 by "George Oro" <george@c...> on Tue, 22 Oct 2002 18:52:00 +0400
Thanks John, but I got an error "Method or data member not found" and the AddItem is highlighted.
This is what I did, I put the below code on my Form Load:

Assuming cn is my ADODB Connection

    'Populate Job Title ComboBox
    Dim rsJobTitle as ADODB.Recordset
    Dim strJobTitle As String
    strJobTitle = "SELECT * FROM d57TblJobTitle ORDER BY d57JobTitle"
    
    Set rsJobTitle = New ADODB.Recordset
    rsJobTitle.CursorType = adOpenStatic
    rsJobTitle.CursorLocation = adUseClient
    rsJobTitle.LockType = adLockOptimistic
    rsJobTitle.Open strJobTitle, cn

    With rsJobTitle
        .MoveFirst
        Do Until .EOF
            Me.txtJobTitle.AddItem !d57JobTitle
            .MoveNext
        Loop
    End With
============================================

Did I miss something?
TIA,
George



-----Original Message-----
From: John Pace [mailto:jpace@h...]
Sent: Tuesday, October 22, 2002 6:02 PM
To: Access
Subject: [access] RE: Populate (AddItem) in ComboBox


George, 

Do the following (I am assuming you are using a recordset call
rstJobTitle).
If you want to add all the records in the recordset to the combo box do
the following:

With rstJobTitle

	.MoveFirst

	Do Until .EOF

		ComboBox.AddItem !d57JobTitleID & " - " & !d57JobTitle
		
		.MoveNext

	Loop

End With

Hope that helps,

John

-----Original Message-----
From: George Oro [mailto:george@c...] 
Sent: Tuesday, October 22, 2002 7:50 AM
To: Access
Subject: [access] Populate (AddItem) in ComboBox

Thanks Bob for your idea and tips on my below post "Binding Fields".

By the way, how can I populate or add item on my combo box using code?
On my below post, I just add one ComboBox field "Job Title" and I have a
table on my Access2K Back-end called d57TblJobTitle with
the following fields d57JobTitleID & d57JobTitle.

Any help is highly appreciated.
TIA
George ;D

-----Original Message-----
From: Bob Bedell [mailto:bobbedell15@m...]
Sent: Monday, October 21, 2002 9:15 PM
To: Access
Subject: [access] Re: Binding Fields


Hi George,

That's how its done. Why are you using WithEvents in you declaration?
You don't need it in this module. Only recommendation would be: in order
to prevent your cursor from falling off the beginning or end of your
recordset and producing weird error messages, have your navigation
buttons check for the recordsets BOF and EOF properties. The following
code also gives the user some halpful visual cues by enabling and
disabling the appropriate navigation buttons.

Private Sub cmdPrev_Click()

    rsContacts.MovePrevious
    txtContactsID.SetFocus
    rsContacts.MovePrevious
    If rsContacts.BOF Then
        cmdPrev.Enabled = False
    Else
        cmdPrev.Enabled = True
    End If
    cmdNext.Enabled = True
    rsContacts.MoveNext

    BindAllFields

End Sub

Private Sub cmdNext_Click()
    rsContacts.MoveNext
    txtContactsID.SetFocus
    rsContacts.MoveNext
    If rsContacts.EOF Then
        cmdNext.Enabled = False
    Else
        cmdNext.Enabled = True
    End If
    rsContacts.MovePrevious
    cmdPrev.Enabled = True

    BindAllFields
End Sub

Best,

Bob

>From: "George Oro" <george@c...>
>Reply-To: "Access" <access@p...>
>To: "Access" <access@p...>
>Subject: [access] Binding Fields
>Date: Mon, 21 Oct 2002 18:16:59 +0400
>
>Hi Guys,
>
>I just started connecting my database using ADODB coding, at present, I
>just have 3 textbox fields and two cmdButton for test with
>the following code:
>QUESTION:
>1) Is my connection OK? otherwise what is the best?
>2) Is there any easiest way to bind my fields accordingly?
>
>Any help and idea is highly appreciated.
>Cheers,
>George
>
>MY CODE
>----------
>Option Compare Database
>Option Explicit
>Dim WithEvents rsContacts As ADODB.Recordset
>----------
>
>Private Sub Form_Open(Cancel As Integer)
>     'Database Connection
>     Dim cn As ADODB.Connection
>     Dim strCn As String
>
>     Set cn = New ADODB.Connection
>     strCn = "Provider=Microsoft.Jet.OLEDB.4.0;Data
>Source=C:\Database\MyVBapp\Communicator ComData.mdb;Persist Security
>Info=False"
>     cn.Open strCn
>
>     'Recordset Connection
>     'Dim rsContacts As ADODB.Recordset
>     Dim strRSContacts As String
>
>     Set rsContacts = New ADODB.Recordset
>     strRSContacts = "SELECT * FROM m01TblContacts"
>     rsContacts.Open strRSContacts, cn, adOpenStatic, adLockOptimistic
>
>     BindAllFields
>
>End Sub
>----------------
>Private Sub BindAllFields()
>     With Me
>         .txtContactsID = rsContacts("m01ContactsID")
>         .txtFirstName = rsContacts("m01FirstName")
>         .txtLastName = rsContacts("m01LastName")
>     End With
>End Sub
>---------------
>Private Sub cmdNext_Click()
>On Error GoTo Err_cmdNext_Click
>
>
>     rsContacts.MoveNext
>     BindAllFields
>
>Exit_cmdNext_Click:
>     Exit Sub
>
>Err_cmdNext_Click:
>     MsgBox Err.Description
>     Resume Exit_cmdNext_Click
>
>End Sub
>----------------
>Private Sub cmdPrev_Click()
>On Error GoTo Err_cmdPrev_Click
>
>
>     rsContacts.MovePrevious
>     BindAllFields
>
>Exit_cmdPrev_Click:
>     Exit Sub
>
>Err_cmdPrev_Click:
>     MsgBox Err.Description
>     Resume Exit_cmdPrev_Click
>
>End Sub
>
>


_________________________________________________________________
Choose an Internet access plan right for you -- try MSN!
http://resourcecenter.msn.com/access/plans/default.asp







Message #4 by "Bob Bedell" <bobbedell15@m...> on Tue, 22 Oct 2002 13:01:57 -0400
George,

Try the following. I added two things  to John's code. First, the line

cboJobTitle.RowSourceType = "Value List"

The AddItem method will only work if the control's rowsource type is a Value
List.
Second, the With block:

 With cboJobTitle
        .SetFocus
        .Text = cboJobTitle.ItemData(0)
    End With

This will display the first value of the Value List in the combo boxes text
area. Without
this code, the combo will be populated, but nothing will be displayed by
default.

'~~~~~~~~~~Start~~~~~~~~~~

Private Sub Form_Open(Cancel As Integer)
    Dim cnn As ADODB.Connection
    Dim rst As ADODB.Recordset
    Dim strList As String
    Dim strSQL As String

    strSQL = "SELECT d57JobTitleID, d57JobTitle FROM d57TblJobTitle " _
       & "ORDER BY d57JobTitleID"

    Set cnn = CurrentProject.Connection

    Set rst = New ADODB.Recordset
    rst.Open strSQL, cnn, adOpenForwardOnly, adLockReadOnly

    cboJobTitle.RowSourceType = "Value List"

    With rst
        .MoveFirst
        Do Until .EOF
            cboJobTitle.AddItem !d57JobTitleID & " - " & !d57JobTitle
            .MoveNext
        Loop
    End With

    With cboJobTitle
        .SetFocus
        .Text = cboJobTitle.ItemData(0)
    End With

    rst.Close

    Set rst = Nothing
    Set cnn = Nothing
End Sub

'~~~~~~~~~~Stop~~~~~~~~~~

If you feel like playing around with arrays a bit, the following code uses
the GetRows method of the recordset object which returns a two-dimensional
array.
The array's values are assigned to the combo boxes rowsource property.

'~~~~~~~~~~Start~~~~~~~~~~

Private Sub Form_Open(Cancel As Integer)
    Dim cnn As ADODB.Connection
    Dim rst As ADODB.Recordset
    Dim strList As String
    Dim strSQL As String

    strSQL = "SELECT d57JobTitle FROM d57TblJobTitle " _
       & "ORDER BY d57JobTitle"

    Set cnn = CurrentProject.Connection

    Set rst = New ADODB.Recordset
    rst.Open strSQL, cnn, adOpenForwardOnly, adLockReadOnly

    strList = BuildString(rst)
    With cboJobTitle
        .RowSource = strList
        .RowSourceType = "Value List"
        .SetFocus
        .Text = cboJobTitle.ItemData(0)
    End With
    rst.Close

    Set rst = Nothing
    Set cnn = Nothing
End Sub

Private Function BuildString(rst As ADODB.Recordset) As String
    Dim strReturn As String
    Dim varItems As Variant
    Dim x As Integer
    Dim y As Integer

    rst.MoveFirst

    varItems = rst.GetRows(10)
    For x = LBound(varItems, 2) To UBound(varItems, 2)
        For y = LBound(varItems, 1) To UBound(varItems, 1)
            strReturn = strReturn & varItems(y, x) & ";"
        Next y
    Next x
    BuildString = strReturn
End Function

'~~~~~~~~~~Stop~~~~~~~~~~

Best,

Bob





----- Original Message -----
From: "George Oro" <george@c...>
To: "Access" <access@p...>
Sent: Tuesday, October 22, 2002 10:52 AM
Subject: [access] RE: Populate (AddItem) in ComboBox


> Thanks John, but I got an error "Method or data member not found" and the
AddItem is highlighted.
> This is what I did, I put the below code on my Form Load:
>
> Assuming cn is my ADODB Connection
>
>     'Populate Job Title ComboBox
>     Dim rsJobTitle as ADODB.Recordset
>     Dim strJobTitle As String
>     strJobTitle = "SELECT * FROM d57TblJobTitle ORDER BY d57JobTitle"
>
>     Set rsJobTitle = New ADODB.Recordset
>     rsJobTitle.CursorType = adOpenStatic
>     rsJobTitle.CursorLocation = adUseClient
>     rsJobTitle.LockType = adLockOptimistic
>     rsJobTitle.Open strJobTitle, cn
>
>     With rsJobTitle
>         .MoveFirst
>         Do Until .EOF
>             Me.txtJobTitle.AddItem !d57JobTitle
>             .MoveNext
>         Loop
>     End With
> ============================================
>
> Did I miss something?
> TIA,
> George
>
>
>
> -----Original Message-----
> From: John Pace [mailto:jpace@h...]
> Sent: Tuesday, October 22, 2002 6:02 PM
> To: Access
> Subject: [access] RE: Populate (AddItem) in ComboBox
>
>
> George,
>
> Do the following (I am assuming you are using a recordset call
> rstJobTitle).
> If you want to add all the records in the recordset to the combo box do
> the following:
>
> With rstJobTitle
>
> .MoveFirst
>
> Do Until .EOF
>
> ComboBox.AddItem !d57JobTitleID & " - " & !d57JobTitle
>
> .MoveNext
>
> Loop
>
> End With
>
> Hope that helps,
>
> John
>
> -----Original Message-----
> From: George Oro [mailto:george@c...]
> Sent: Tuesday, October 22, 2002 7:50 AM
> To: Access
> Subject: [access] Populate (AddItem) in ComboBox
>
> Thanks Bob for your idea and tips on my below post "Binding Fields".
>
> By the way, how can I populate or add item on my combo box using code?
> On my below post, I just add one ComboBox field "Job Title" and I have a
> table on my Access2K Back-end called d57TblJobTitle with
> the following fields d57JobTitleID & d57JobTitle.
>
> Any help is highly appreciated.
> TIA
> George ;D
>
> -----Original Message-----
> From: Bob Bedell [mailto:bobbedell15@m...]
> Sent: Monday, October 21, 2002 9:15 PM
> To: Access
> Subject: [access] Re: Binding Fields
>
>
> Hi George,
>
> That's how its done. Why are you using WithEvents in you declaration?
> You don't need it in this module. Only recommendation would be: in order
> to prevent your cursor from falling off the beginning or end of your
> recordset and producing weird error messages, have your navigation
> buttons check for the recordsets BOF and EOF properties. The following
> code also gives the user some halpful visual cues by enabling and
> disabling the appropriate navigation buttons.
>
> Private Sub cmdPrev_Click()
>
>     rsContacts.MovePrevious
>     txtContactsID.SetFocus
>     rsContacts.MovePrevious
>     If rsContacts.BOF Then
>         cmdPrev.Enabled = False
>     Else
>         cmdPrev.Enabled = True
>     End If
>     cmdNext.Enabled = True
>     rsContacts.MoveNext
>
>     BindAllFields
>
> End Sub
>
> Private Sub cmdNext_Click()
>     rsContacts.MoveNext
>     txtContactsID.SetFocus
>     rsContacts.MoveNext
>     If rsContacts.EOF Then
>         cmdNext.Enabled = False
>     Else
>         cmdNext.Enabled = True
>     End If
>     rsContacts.MovePrevious
>     cmdPrev.Enabled = True
>
>     BindAllFields
> End Sub
>
> Best,
>
> Bob
>
> >From: "George Oro" <george@c...>
> >Reply-To: "Access" <access@p...>
> >To: "Access" <access@p...>
> >Subject: [access] Binding Fields
> >Date: Mon, 21 Oct 2002 18:16:59 +0400
> >
> >Hi Guys,
> >
> >I just started connecting my database using ADODB coding, at present, I
> >just have 3 textbox fields and two cmdButton for test with
> >the following code:
> >QUESTION:
> >1) Is my connection OK? otherwise what is the best?
> >2) Is there any easiest way to bind my fields accordingly?
> >
> >Any help and idea is highly appreciated.
> >Cheers,
> >George
> >
> >MY CODE
> >----------
> >Option Compare Database
> >Option Explicit
> >Dim WithEvents rsContacts As ADODB.Recordset
> >----------
> >
> >Private Sub Form_Open(Cancel As Integer)
> >     'Database Connection
> >     Dim cn As ADODB.Connection
> >     Dim strCn As String
> >
> >     Set cn = New ADODB.Connection
> >     strCn = "Provider=Microsoft.Jet.OLEDB.4.0;Data
> >Source=C:\Database\MyVBapp\Communicator ComData.mdb;Persist Security
> >Info=False"
> >     cn.Open strCn
> >
> >     'Recordset Connection
> >     'Dim rsContacts As ADODB.Recordset
> >     Dim strRSContacts As String
> >
> >     Set rsContacts = New ADODB.Recordset
> >     strRSContacts = "SELECT * FROM m01TblContacts"
> >     rsContacts.Open strRSContacts, cn, adOpenStatic, adLockOptimistic
> >
> >     BindAllFields
> >
> >End Sub
> >----------------
> >Private Sub BindAllFields()
> >     With Me
> >         .txtContactsID = rsContacts("m01ContactsID")
> >         .txtFirstName = rsContacts("m01FirstName")
> >         .txtLastName = rsContacts("m01LastName")
> >     End With
> >End Sub
> >---------------
> >Private Sub cmdNext_Click()
> >On Error GoTo Err_cmdNext_Click
> >
> >
> >     rsContacts.MoveNext
> >     BindAllFields
> >
> >Exit_cmdNext_Click:
> >     Exit Sub
> >
> >Err_cmdNext_Click:
> >     MsgBox Err.Description
> >     Resume Exit_cmdNext_Click
> >
> >End Sub
> >----------------
> >Private Sub cmdPrev_Click()
> >On Error GoTo Err_cmdPrev_Click
> >
> >
> >     rsContacts.MovePrevious
> >     BindAllFields
> >
> >Exit_cmdPrev_Click:
> >     Exit Sub
> >
> >Err_cmdPrev_Click:
> >     MsgBox Err.Description
> >     Resume Exit_cmdPrev_Click
> >
> >End Sub
> >
> >
>
>
> _________________________________________________________________
> Choose an Internet access plan right for you -- try MSN!
> http://resourcecenter.msn.com/access/plans/default.asp
>
>
>
>
>
>
>
>
>
Message #5 by "George Oro" <george@c...> on Wed, 23 Oct 2002 08:46:40 +0400
Hi Bob,
Thanks for your tips but still it didn't work, same error. By the way, I don't have any single table lying or linked in this app.
This is my Fron-end, and I'm accessing all my tables on my Back-end. Here below the current code on my Form_Open:

=====================================
Private Sub Form_Open(Cancel As Integer)
    'Database Connection
    Dim cn As ADODB.Connection
    Dim strCn As String

    Set cn = New ADODB.Connection
    strCn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Database\MyVBapp\Communicator\ComData.mdb;Persist Security Info=False"
    cn.Open strCn

    'Recordset Connection
    Dim strRSContacts As String

    Set rsContacts = New ADODB.Recordset
    strRSContacts = "SELECT * FROM m01TblContacts"
    rsContacts.Open strRSContacts, cn, adOpenStatic, adLockOptimistic

    'Populate Job Title ComboBox
    Dim rsJobTitle As ADODB.Recordset
    Dim strJobTitle As String
    strJobTitle = "SELECT d57JobTitleID, d57JobTitle FROM d57TblJobTitle " _
       & "ORDER BY d57JobTitleID"

    Set rsJobTitle = New ADODB.Recordset
    rsJobTitle.Open strJobTitle, cn, adOpenForwardOnly, adLockReadOnly

    txtJobTitle.RowSourceType = "Value List"

    With rsJobTitle
        .MoveFirst
        Do Until .EOF
            txtJobTitle.AddItem !d57JobTitleID & " - " & !d57JobTitle
            .MoveNext
        Loop
    End With

    With txtJobTitle
        .SetFocus
        .Text = txtJobTitle.ItemData(0)
    End With

end ================

-----Original Message-----
From: Bob Bedell [mailto:bobbedell15@m...]
Sent: Tuesday, October 22, 2002 9:02 PM
To: Access
Subject: [access] RE: Populate (AddItem) in ComboBox


George,

Try the following. I added two things  to John's code. First, the line

cboJobTitle.RowSourceType = "Value List"

The AddItem method will only work if the control's rowsource type is a Value
List.
Second, the With block:

 With cboJobTitle
        .SetFocus
        .Text = cboJobTitle.ItemData(0)
    End With

This will display the first value of the Value List in the combo boxes text
area. Without
this code, the combo will be populated, but nothing will be displayed by
default.

'~~~~~~~~~~Start~~~~~~~~~~

Private Sub Form_Open(Cancel As Integer)
    Dim cnn As ADODB.Connection
    Dim rst As ADODB.Recordset
    Dim strList As String
    Dim strSQL As String

    strSQL = "SELECT d57JobTitleID, d57JobTitle FROM d57TblJobTitle " _
       & "ORDER BY d57JobTitleID"

    Set cnn = CurrentProject.Connection

    Set rst = New ADODB.Recordset
    rst.Open strSQL, cnn, adOpenForwardOnly, adLockReadOnly

    cboJobTitle.RowSourceType = "Value List"

    With rst
        .MoveFirst
        Do Until .EOF
            cboJobTitle.AddItem !d57JobTitleID & " - " & !d57JobTitle
            .MoveNext
        Loop
    End With

    With cboJobTitle
        .SetFocus
        .Text = cboJobTitle.ItemData(0)
    End With

    rst.Close

    Set rst = Nothing
    Set cnn = Nothing
End Sub

'~~~~~~~~~~Stop~~~~~~~~~~

If you feel like playing around with arrays a bit, the following code uses
the GetRows method of the recordset object which returns a two-dimensional
array.
The array's values are assigned to the combo boxes rowsource property.

'~~~~~~~~~~Start~~~~~~~~~~

Private Sub Form_Open(Cancel As Integer)
    Dim cnn As ADODB.Connection
    Dim rst As ADODB.Recordset
    Dim strList As String
    Dim strSQL As String

    strSQL = "SELECT d57JobTitle FROM d57TblJobTitle " _
       & "ORDER BY d57JobTitle"

    Set cnn = CurrentProject.Connection

    Set rst = New ADODB.Recordset
    rst.Open strSQL, cnn, adOpenForwardOnly, adLockReadOnly

    strList = BuildString(rst)
    With cboJobTitle
        .RowSource = strList
        .RowSourceType = "Value List"
        .SetFocus
        .Text = cboJobTitle.ItemData(0)
    End With
    rst.Close

    Set rst = Nothing
    Set cnn = Nothing
End Sub

Private Function BuildString(rst As ADODB.Recordset) As String
    Dim strReturn As String
    Dim varItems As Variant
    Dim x As Integer
    Dim y As Integer

    rst.MoveFirst

    varItems = rst.GetRows(10)
    For x = LBound(varItems, 2) To UBound(varItems, 2)
        For y = LBound(varItems, 1) To UBound(varItems, 1)
            strReturn = strReturn & varItems(y, x) & ";"
        Next y
    Next x
    BuildString = strReturn
End Function

'~~~~~~~~~~Stop~~~~~~~~~~

Best,

Bob





----- Original Message -----
From: "George Oro" <george@c...>
To: "Access" <access@p...>
Sent: Tuesday, October 22, 2002 10:52 AM
Subject: [access] RE: Populate (AddItem) in ComboBox


> Thanks John, but I got an error "Method or data member not found" and the
AddItem is highlighted.
> This is what I did, I put the below code on my Form Load:
>
> Assuming cn is my ADODB Connection
>
>     'Populate Job Title ComboBox
>     Dim rsJobTitle as ADODB.Recordset
>     Dim strJobTitle As String
>     strJobTitle = "SELECT * FROM d57TblJobTitle ORDER BY d57JobTitle"
>
>     Set rsJobTitle = New ADODB.Recordset
>     rsJobTitle.CursorType = adOpenStatic
>     rsJobTitle.CursorLocation = adUseClient
>     rsJobTitle.LockType = adLockOptimistic
>     rsJobTitle.Open strJobTitle, cn
>
>     With rsJobTitle
>         .MoveFirst
>         Do Until .EOF
>             Me.txtJobTitle.AddItem !d57JobTitle
>             .MoveNext
>         Loop
>     End With
> ============================================
>
> Did I miss something?
> TIA,
> George
>
>
>
> -----Original Message-----
> From: John Pace [mailto:jpace@h...]
> Sent: Tuesday, October 22, 2002 6:02 PM
> To: Access
> Subject: [access] RE: Populate (AddItem) in ComboBox
>
>
> George,
>
> Do the following (I am assuming you are using a recordset call
> rstJobTitle).
> If you want to add all the records in the recordset to the combo box do
> the following:
>
> With rstJobTitle
>
> .MoveFirst
>
> Do Until .EOF
>
> ComboBox.AddItem !d57JobTitleID & " - " & !d57JobTitle
>
> .MoveNext
>
> Loop
>
> End With
>
> Hope that helps,
>
> John
>
> -----Original Message-----
> From: George Oro [mailto:george@c...]
> Sent: Tuesday, October 22, 2002 7:50 AM
> To: Access
> Subject: [access] Populate (AddItem) in ComboBox
>
> Thanks Bob for your idea and tips on my below post "Binding Fields".
>
> By the way, how can I populate or add item on my combo box using code?
> On my below post, I just add one ComboBox field "Job Title" and I have a
> table on my Access2K Back-end called d57TblJobTitle with
> the following fields d57JobTitleID & d57JobTitle.
>
> Any help is highly appreciated.
> TIA
> George ;D
>
> -----Original Message-----
> From: Bob Bedell [mailto:bobbedell15@m...]
> Sent: Monday, October 21, 2002 9:15 PM
> To: Access
> Subject: [access] Re: Binding Fields
>
>
> Hi George,
>
> That's how its done. Why are you using WithEvents in you declaration?
> You don't need it in this module. Only recommendation would be: in order
> to prevent your cursor from falling off the beginning or end of your
> recordset and producing weird error messages, have your navigation
> buttons check for the recordsets BOF and EOF properties. The following
> code also gives the user some halpful visual cues by enabling and
> disabling the appropriate navigation buttons.
>
> Private Sub cmdPrev_Click()
>
>     rsContacts.MovePrevious
>     txtContactsID.SetFocus
>     rsContacts.MovePrevious
>     If rsContacts.BOF Then
>         cmdPrev.Enabled = False
>     Else
>         cmdPrev.Enabled = True
>     End If
>     cmdNext.Enabled = True
>     rsContacts.MoveNext
>
>     BindAllFields
>
> End Sub
>
> Private Sub cmdNext_Click()
>     rsContacts.MoveNext
>     txtContactsID.SetFocus
>     rsContacts.MoveNext
>     If rsContacts.EOF Then
>         cmdNext.Enabled = False
>     Else
>         cmdNext.Enabled = True
>     End If
>     rsContacts.MovePrevious
>     cmdPrev.Enabled = True
>
>     BindAllFields
> End Sub
>
> Best,
>
> Bob
>
> >From: "George Oro" <george@c...>
> >Reply-To: "Access" <access@p...>
> >To: "Access" <access@p...>
> >Subject: [access] Binding Fields
> >Date: Mon, 21 Oct 2002 18:16:59 +0400
> >
> >Hi Guys,
> >
> >I just started connecting my database using ADODB coding, at present, I
> >just have 3 textbox fields and two cmdButton for test with
> >the following code:
> >QUESTION:
> >1) Is my connection OK? otherwise what is the best?
> >2) Is there any easiest way to bind my fields accordingly?
> >
> >Any help and idea is highly appreciated.
> >Cheers,
> >George
> >
> >MY CODE
> >----------
> >Option Compare Database
> >Option Explicit
> >Dim WithEvents rsContacts As ADODB.Recordset
> >----------
> >
> >Private Sub Form_Open(Cancel As Integer)
> >     'Database Connection
> >     Dim cn As ADODB.Connection
> >     Dim strCn As String
> >
> >     Set cn = New ADODB.Connection
> >     strCn = "Provider=Microsoft.Jet.OLEDB.4.0;Data
> >Source=C:\Database\MyVBapp\Communicator ComData.mdb;Persist Security
> >Info=False"
> >     cn.Open strCn
> >
> >     'Recordset Connection
> >     'Dim rsContacts As ADODB.Recordset
> >     Dim strRSContacts As String
> >
> >     Set rsContacts = New ADODB.Recordset
> >     strRSContacts = "SELECT * FROM m01TblContacts"
> >     rsContacts.Open strRSContacts, cn, adOpenStatic, adLockOptimistic
> >
> >     BindAllFields
> >
> >End Sub
> >----------------
> >Private Sub BindAllFields()
> >     With Me
> >         .txtContactsID = rsContacts("m01ContactsID")
> >         .txtFirstName = rsContacts("m01FirstName")
> >         .txtLastName = rsContacts("m01LastName")
> >     End With
> >End Sub
> >---------------
> >Private Sub cmdNext_Click()
> >On Error GoTo Err_cmdNext_Click
> >
> >
> >     rsContacts.MoveNext
> >     BindAllFields
> >
> >Exit_cmdNext_Click:
> >     Exit Sub
> >
> >Err_cmdNext_Click:
> >     MsgBox Err.Description
> >     Resume Exit_cmdNext_Click
> >
> >End Sub
> >----------------
> >Private Sub cmdPrev_Click()
> >On Error GoTo Err_cmdPrev_Click
> >
> >
> >     rsContacts.MovePrevious
> >     BindAllFields
> >
> >Exit_cmdPrev_Click:
> >     Exit Sub
> >
> >Err_cmdPrev_Click:
> >     MsgBox Err.Description
> >     Resume Exit_cmdPrev_Click
> >
> >End Sub
> >
> >
>
>
> _________________________________________________________________
> Choose an Internet access plan right for you -- try MSN!
> http://resourcecenter.msn.com/access/plans/default.asp
>
>
>
>
>
>
>
>
>


Message #6 by "Bob Bedell" <bobbedell15@m...> on Wed, 23 Oct 2002 05:37:19 +0000
Hi George,

Don't know what to tell ya'. I just pasted your code behind
my form, and the combo box filled and displayed without a hitch.

I commented out:

' 'Recordset Connection
' Dim strRSContacts As String
'
' Set rsContacts = New ADODB.Recordset
' strRSContacts = "SELECT * FROM m01TblContacts"
' rsContacts.Open strRSContacts, cn, adOpenStatic, adLockOptimistic

which I assume is your forms recordsource.  And I changed your
connection string to:

Set cn = CurrentProject.Connection

(my table is local). It should'nt make any difference to Access where your 
tables are physically, but for testing purposes maybe import them;
just one less thing to go wrong. And check your design-time combo
box properties. Both Row Source and Row Source Type should be null.

Thats about the best I can do. Its running OK here.

Best,

Bob

>From: "George Oro" <george@c...>
>Reply-To: "Access" <access@p...>
>To: "Access" <access@p...>
>Subject: [access] RE: Populate (AddItem) in ComboBox
>Date: Wed, 23 Oct 2002 08:46:40 +0400
>
>Hi Bob,
>Thanks for your tips but still it didn't work, same error. By the way, I 
>don't have any single table lying or linked in this app.
>This is my Fron-end, and I'm accessing all my tables on my Back-end. Here 
>below the current code on my Form_Open:
>
>=====================================
>Private Sub Form_Open(Cancel As Integer)
>     'Database Connection
>     Dim cn As ADODB.Connection
>     Dim strCn As String
>
>     Set cn = New ADODB.Connection
>     strCn = "Provider=Microsoft.Jet.OLEDB.4.0;Data 
>Source=C:\Database\MyVBapp\Communicator\ComData.mdb;Persist Security 
>Info=False"
>     cn.Open strCn
>
>     'Recordset Connection
>     Dim strRSContacts As String
>
>     Set rsContacts = New ADODB.Recordset
>     strRSContacts = "SELECT * FROM m01TblContacts"
>     rsContacts.Open strRSContacts, cn, adOpenStatic, adLockOptimistic
>
>     'Populate Job Title ComboBox
>     Dim rsJobTitle As ADODB.Recordset
>     Dim strJobTitle As String
>     strJobTitle = "SELECT d57JobTitleID, d57JobTitle FROM d57TblJobTitle " 
>_
>        & "ORDER BY d57JobTitleID"
>
>     Set rsJobTitle = New ADODB.Recordset
>     rsJobTitle.Open strJobTitle, cn, adOpenForwardOnly, adLockReadOnly
>
>     txtJobTitle.RowSourceType = "Value List"
>
>     With rsJobTitle
>         .MoveFirst
>         Do Until .EOF
>             txtJobTitle.AddItem !d57JobTitleID & " - " & !d57JobTitle
>             .MoveNext
>         Loop
>     End With
>
>     With txtJobTitle
>         .SetFocus
>         .Text = txtJobTitle.ItemData(0)
>     End With
>
>end ================
>
>-----Original Message-----
>From: Bob Bedell [mailto:bobbedell15@m...]
>Sent: Tuesday, October 22, 2002 9:02 PM
>To: Access
>Subject: [access] RE: Populate (AddItem) in ComboBox
>
>
>George,
>
>Try the following. I added two things  to John's code. First, the line
>
>cboJobTitle.RowSourceType = "Value List"
>
>The AddItem method will only work if the control's rowsource type is a 
>Value
>List.
>Second, the With block:
>
>  With cboJobTitle
>         .SetFocus
>         .Text = cboJobTitle.ItemData(0)
>     End With
>
>This will display the first value of the Value List in the combo boxes text
>area. Without
>this code, the combo will be populated, but nothing will be displayed by
>default.
>
>'~~~~~~~~~~Start~~~~~~~~~~
>
>Private Sub Form_Open(Cancel As Integer)
>     Dim cnn As ADODB.Connection
>     Dim rst As ADODB.Recordset
>     Dim strList As String
>     Dim strSQL As String
>
>     strSQL = "SELECT d57JobTitleID, d57JobTitle FROM d57TblJobTitle " _
>        & "ORDER BY d57JobTitleID"
>
>     Set cnn = CurrentProject.Connection
>
>     Set rst = New ADODB.Recordset
>     rst.Open strSQL, cnn, adOpenForwardOnly, adLockReadOnly
>
>     cboJobTitle.RowSourceType = "Value List"
>
>     With rst
>         .MoveFirst
>         Do Until .EOF
>             cboJobTitle.AddItem !d57JobTitleID & " - " & !d57JobTitle
>             .MoveNext
>         Loop
>     End With
>
>     With cboJobTitle
>         .SetFocus
>         .Text = cboJobTitle.ItemData(0)
>     End With
>
>     rst.Close
>
>     Set rst = Nothing
>     Set cnn = Nothing
>End Sub
>
>'~~~~~~~~~~Stop~~~~~~~~~~
>
>If you feel like playing around with arrays a bit, the following code uses
>the GetRows method of the recordset object which returns a two-dimensional
>array.
>The array's values are assigned to the combo boxes rowsource property.
>
>'~~~~~~~~~~Start~~~~~~~~~~
>
>Private Sub Form_Open(Cancel As Integer)
>     Dim cnn As ADODB.Connection
>     Dim rst As ADODB.Recordset
>     Dim strList As String
>     Dim strSQL As String
>
>     strSQL = "SELECT d57JobTitle FROM d57TblJobTitle " _
>        & "ORDER BY d57JobTitle"
>
>     Set cnn = CurrentProject.Connection
>
>     Set rst = New ADODB.Recordset
>     rst.Open strSQL, cnn, adOpenForwardOnly, adLockReadOnly
>
>     strList = BuildString(rst)
>     With cboJobTitle
>         .RowSource = strList
>         .RowSourceType = "Value List"
>         .SetFocus
>         .Text = cboJobTitle.ItemData(0)
>     End With
>     rst.Close
>
>     Set rst = Nothing
>     Set cnn = Nothing
>End Sub
>
>Private Function BuildString(rst As ADODB.Recordset) As String
>     Dim strReturn As String
>     Dim varItems As Variant
>     Dim x As Integer
>     Dim y As Integer
>
>     rst.MoveFirst
>
>     varItems = rst.GetRows(10)
>     For x = LBound(varItems, 2) To UBound(varItems, 2)
>         For y = LBound(varItems, 1) To UBound(varItems, 1)
>             strReturn = strReturn & varItems(y, x) & ";"
>         Next y
>     Next x
>     BuildString = strReturn
>End Function
>
>'~~~~~~~~~~Stop~~~~~~~~~~
>
>Best,
>
>Bob
>
>
>
>
>
>----- Original Message -----
>From: "George Oro" <george@c...>
>To: "Access" <access@p...>
>Sent: Tuesday, October 22, 2002 10:52 AM
>Subject: [access] RE: Populate (AddItem) in ComboBox
>
>
> > Thanks John, but I got an error "Method or data member not found" and 
>the
>AddItem is highlighted.
> > This is what I did, I put the below code on my Form Load:
> >
> > Assuming cn is my ADODB Connection
> >
> >     'Populate Job Title ComboBox
> >     Dim rsJobTitle as ADODB.Recordset
> >     Dim strJobTitle As String
> >     strJobTitle = "SELECT * FROM d57TblJobTitle ORDER BY d57JobTitle"
> >
> >     Set rsJobTitle = New ADODB.Recordset
> >     rsJobTitle.CursorType = adOpenStatic
> >     rsJobTitle.CursorLocation = adUseClient
> >     rsJobTitle.LockType = adLockOptimistic
> >     rsJobTitle.Open strJobTitle, cn
> >
> >     With rsJobTitle
> >         .MoveFirst
> >         Do Until .EOF
> >             Me.txtJobTitle.AddItem !d57JobTitle
> >             .MoveNext
> >         Loop
> >     End With
> > ============================================
> >
> > Did I miss something?
> > TIA,
> > George
> >
> >
> >
> > -----Original Message-----
> > From: John Pace [mailto:jpace@h...]
> > Sent: Tuesday, October 22, 2002 6:02 PM
> > To: Access
> > Subject: [access] RE: Populate (AddItem) in ComboBox
> >
> >
> > George,
> >
> > Do the following (I am assuming you are using a recordset call
> > rstJobTitle).
> > If you want to add all the records in the recordset to the combo box do
> > the following:
> >
> > With rstJobTitle
> >
> > .MoveFirst
> >
> > Do Until .EOF
> >
> > ComboBox.AddItem !d57JobTitleID & " - " & !d57JobTitle
> >
> > .MoveNext
> >
> > Loop
> >
> > End With
> >
> > Hope that helps,
> >
> > John
> >
> > -----Original Message-----
> > From: George Oro [mailto:george@c...]
> > Sent: Tuesday, October 22, 2002 7:50 AM
> > To: Access
> > Subject: [access] Populate (AddItem) in ComboBox
> >
> > Thanks Bob for your idea and tips on my below post "Binding Fields".
> >
> > By the way, how can I populate or add item on my combo box using code?
> > On my below post, I just add one ComboBox field "Job Title" and I have a
> > table on my Access2K Back-end called d57TblJobTitle with
> > the following fields d57JobTitleID & d57JobTitle.
> >
> > Any help is highly appreciated.
> > TIA
> > George ;D
> >
> > -----Original Message-----
> > From: Bob Bedell [mailto:bobbedell15@m...]
> > Sent: Monday, October 21, 2002 9:15 PM
> > To: Access
> > Subject: [access] Re: Binding Fields
> >
> >
> > Hi George,
> >
> > That's how its done. Why are you using WithEvents in you declaration?
> > You don't need it in this module. Only recommendation would be: in order
> > to prevent your cursor from falling off the beginning or end of your
> > recordset and producing weird error messages, have your navigation
> > buttons check for the recordsets BOF and EOF properties. The following
> > code also gives the user some halpful visual cues by enabling and
> > disabling the appropriate navigation buttons.
> >
> > Private Sub cmdPrev_Click()
> >
> >     rsContacts.MovePrevious
> >     txtContactsID.SetFocus
> >     rsContacts.MovePrevious
> >     If rsContacts.BOF Then
> >         cmdPrev.Enabled = False
> >     Else
> >         cmdPrev.Enabled = True
> >     End If
> >     cmdNext.Enabled = True
> >     rsContacts.MoveNext
> >
> >     BindAllFields
> >
> > End Sub
> >
> > Private Sub cmdNext_Click()
> >     rsContacts.MoveNext
> >     txtContactsID.SetFocus
> >     rsContacts.MoveNext
> >     If rsContacts.EOF Then
> >         cmdNext.Enabled = False
> >     Else
> >         cmdNext.Enabled = True
> >     End If
> >     rsContacts.MovePrevious
> >     cmdPrev.Enabled = True
> >
> >     BindAllFields
> > End Sub
> >
> > Best,
> >
> > Bob
> >
> > >From: "George Oro" <george@c...>
> > >Reply-To: "Access" <access@p...>
> > >To: "Access" <access@p...>
> > >Subject: [access] Binding Fields
> > >Date: Mon, 21 Oct 2002 18:16:59 +0400
> > >
> > >Hi Guys,
> > >
> > >I just started connecting my database using ADODB coding, at present, I
> > >just have 3 textbox fields and two cmdButton for test with
> > >the following code:
> > >QUESTION:
> > >1) Is my connection OK? otherwise what is the best?
> > >2) Is there any easiest way to bind my fields accordingly?
> > >
> > >Any help and idea is highly appreciated.
> > >Cheers,
> > >George
> > >
> > >MY CODE
> > >----------
> > >Option Compare Database
> > >Option Explicit
> > >Dim WithEvents rsContacts As ADODB.Recordset
> > >----------
> > >
> > >Private Sub Form_Open(Cancel As Integer)
> > >     'Database Connection
> > >     Dim cn As ADODB.Connection
> > >     Dim strCn As String
> > >
> > >     Set cn = New ADODB.Connection
> > >     strCn = "Provider=Microsoft.Jet.OLEDB.4.0;Data
> > >Source=C:\Database\MyVBapp\Communicator ComData.mdb;Persist Security
> > >Info=False"
> > >     cn.Open strCn
> > >
> > >     'Recordset Connection
> > >     'Dim rsContacts As ADODB.Recordset
> > >     Dim strRSContacts As String
> > >
> > >     Set rsContacts = New ADODB.Recordset
> > >     strRSContacts = "SELECT * FROM m01TblContacts"
> > >     rsContacts.Open strRSContacts, cn, adOpenStatic, adLockOptimistic
> > >
> > >     BindAllFields
> > >
> > >End Sub
> > >----------------
> > >Private Sub BindAllFields()
> > >     With Me
> > >         .txtContactsID = rsContacts("m01ContactsID")
> > >         .txtFirstName = rsContacts("m01FirstName")
> > >         .txtLastName = rsContacts("m01LastName")
> > >     End With
> > >End Sub
> > >---------------
> > >Private Sub cmdNext_Click()
> > >On Error GoTo Err_cmdNext_Click
> > >
> > >
> > >     rsContacts.MoveNext
> > >     BindAllFields
> > >
> > >Exit_cmdNext_Click:
> > >     Exit Sub
> > >
> > >Err_cmdNext_Click:
> > >     MsgBox Err.Description
> > >     Resume Exit_cmdNext_Click
> > >
> > >End Sub
> > >----------------
> > >Private Sub cmdPrev_Click()
> > >On Error GoTo Err_cmdPrev_Click
> > >
> > >
> > >     rsContacts.MovePrevious
> > >     BindAllFields
> > >
> > >Exit_cmdPrev_Click:
> > >     Exit Sub
> > >
> > >Err_cmdPrev_Click:
> > >     MsgBox Err.Description
> > >     Resume Exit_cmdPrev_Click
> > >
> > >End Sub
> > >
> > >
> >
> >
> > _________________________________________________________________
> > Choose an Internet access plan right for you -- try MSN!
> > http://resourcecenter.msn.com/access/plans/default.asp
> >
> >
> >
> >
> >
> >
> >
> >
> >
>
>
>


_________________________________________________________________
Surf the Web without missing calls! Get MSN Broadband. 
http://resourcecenter.msn.com/access/plans/freeactivation.asp

Message #7 by "George Oro" <george@c...> on Wed, 23 Oct 2002 12:07:29 +0400
THANK YOU VERY MUCH BOB for your help and time.

Unfortunately, still the same error! don't worry the problem is not your code. I'm very much sure the problem is on my machine or my
access2K. I have some db also using the AddItem and all reference are defined, but when I tried it, I got the same error, I don't
know why suddenly the AddItem cannot be recognized. I run the access Deteck and Repair, and still no luck. I guess I need to
re-install my access2k.

Any other idea before re-installing my acc2k?

Thanks again bob...

cheers,
George

-----Original Message-----
From: Bob Bedell [mailto:bobbedell15@m...]
Sent: Wednesday, October 23, 2002 11:54 AM
To: george@c...
Subject: Re: Populate (AddItem) in ComboBox


Hi George,

Your file is attached. I moved a few things around, added some naming
conventions, added a few navigation buttons and a bunch of navigation
code. Set cnn = CurrentProject.Connection opens your connection. You
don't need to use the Open method of the Connection object in addition.
The form loads OK and the combo fills and displays correctly.
Remember, you only have functionality here to view and navigate the
recordset. Adding, deleting, and updating can't be done with this form
as it stands. Thats the beauty of unbound forms, they take a lot of
work and maintenance.

Your Contacts table could probably benefit from a bit of normalization
(possibly move the repeating groups) and I would definitely use the
JobTitleID field as the primary key of your JobTitles table instead of
the JobTitle field.

Try and get your hands on "Creating Microsoft Access 2000 Solutions"
by Gordon Padwick:

http://www.amazon.com/exec/obidos/tg/detail/-/0672318946/qid=1035359244/sr=8-1/ref=sr_8_1/104-9500173-8464721?v=glance&n=507846

I never did read it, but loved the sample app. Best unbound, ADO
driven, Access front-end sample app I've come across.

Best,

Bob

>From: "George Oro" <george@c...>
>Reply-To: <george@c...>
>To: <bobbedell15@m...>
>Subject: Populate (AddItem) in ComboBox
>Date: Wed, 23 Oct 2002 10:13:36 +0400
>
>Hi Bob,
>Sorry if I didn't as your permission to send this, but I'm getting fade-up.
>I guess I miss something, anyhow, please find below the
>attached file which is my test db.
>
>TIA,
>George
>
>-----Original Message-----
>From: Bob Bedell [mailto:bobbedell15@m...]
>Sent: Wednesday, October 23, 2002 9:37 AM
>To: Access
>Subject: [access] RE: Populate (AddItem) in ComboBox
>
>
>Hi George,
>
>Don't know what to tell ya'. I just pasted your code behind
>my form, and the combo box filled and displayed without a hitch.
>
>I commented out:
>
>' 'Recordset Connection
>' Dim strRSContacts As String
>'
>' Set rsContacts = New ADODB.Recordset
>' strRSContacts = "SELECT * FROM m01TblContacts"
>' rsContacts.Open strRSContacts, cn, adOpenStatic, adLockOptimistic
>
>which I assume is your forms recordsource.  And I changed your
>connection string to:
>
>Set cn = CurrentProject.Connection
>
>(my table is local). It should'nt make any difference to Access where your
>tables are physically, but for testing purposes maybe import them;
>just one less thing to go wrong. And check your design-time combo
>box properties. Both Row Source and Row Source Type should be null.
>
>Thats about the best I can do. Its running OK here.
>
>Best,
>
>Bob
>
> >From: "George Oro" <george@c...>
> >Reply-To: "Access" <access@p...>
> >To: "Access" <access@p...>
> >Subject: [access] RE: Populate (AddItem) in ComboBox
> >Date: Wed, 23 Oct 2002 08:46:40 +0400
> >
> >Hi Bob,
> >Thanks for your tips but still it didn't work, same error. By the way, I
> >don't have any single table lying or linked in this app.
> >This is my Fron-end, and I'm accessing all my tables on my Back-end. Here
> >below the current code on my Form_Open:
> >
> >=====================================
> >Private Sub Form_Open(Cancel As Integer)
> >     'Database Connection
> >     Dim cn As ADODB.Connection
> >     Dim strCn As String
> >
> >     Set cn = New ADODB.Connection
> >     strCn = "Provider=Microsoft.Jet.OLEDB.4.0;Data
> >Source=C:\Database\MyVBapp\Communicator\ComData.mdb;Persist Security
> >Info=False"
> >     cn.Open strCn
> >
> >     'Recordset Connection
> >     Dim strRSContacts As String
> >
> >     Set rsContacts = New ADODB.Recordset
> >     strRSContacts = "SELECT * FROM m01TblContacts"
> >     rsContacts.Open strRSContacts, cn, adOpenStatic, adLockOptimistic
> >
> >     'Populate Job Title ComboBox
> >     Dim rsJobTitle As ADODB.Recordset
> >     Dim strJobTitle As String
> >     strJobTitle = "SELECT d57JobTitleID, d57JobTitle FROM d57TblJobTitle
>"
> >_
> >        & "ORDER BY d57JobTitleID"
> >
> >     Set rsJobTitle = New ADODB.Recordset
> >     rsJobTitle.Open strJobTitle, cn, adOpenForwardOnly, adLockReadOnly
> >
> >     txtJobTitle.RowSourceType = "Value List"
> >
> >     With rsJobTitle
> >         .MoveFirst
> >         Do Until .EOF
> >             txtJobTitle.AddItem !d57JobTitleID & " - " & !d57JobTitle
> >             .MoveNext
> >         Loop
> >     End With
> >
> >     With txtJobTitle
> >         .SetFocus
> >         .Text = txtJobTitle.ItemData(0)
> >     End With
> >
> >end ================
> >
> >-----Original Message-----
> >From: Bob Bedell [mailto:bobbedell15@m...]
> >Sent: Tuesday, October 22, 2002 9:02 PM
> >To: Access
> >Subject: [access] RE: Populate (AddItem) in ComboBox
> >
> >
> >George,
> >
> >Try the following. I added two things  to John's code. First, the line
> >
> >cboJobTitle.RowSourceType = "Value List"
> >
> >The AddItem method will only work if the control's rowsource type is a
> >Value
> >List.
> >Second, the With block:
> >
> >  With cboJobTitle
> >         .SetFocus
> >         .Text = cboJobTitle.ItemData(0)
> >     End With
> >
> >This will display the first value of the Value List in the combo boxes
>text
> >area. Without
> >this code, the combo will be populated, but nothing will be displayed by
> >default.
> >
> >'~~~~~~~~~~Start~~~~~~~~~~
> >
> >Private Sub Form_Open(Cancel As Integer)
> >     Dim cnn As ADODB.Connection
> >     Dim rst As ADODB.Recordset
> >     Dim strList As String
> >     Dim strSQL As String
> >
> >     strSQL = "SELECT d57JobTitleID, d57JobTitle FROM d57TblJobTitle " _
> >        & "ORDER BY d57JobTitleID"
> >
> >     Set cnn = CurrentProject.Connection
> >
> >     Set rst = New ADODB.Recordset
> >     rst.Open strSQL, cnn, adOpenForwardOnly, adLockReadOnly
> >
> >     cboJobTitle.RowSourceType = "Value List"
> >
> >     With rst
> >         .MoveFirst
> >         Do Until .EOF
> >             cboJobTitle.AddItem !d57JobTitleID & " - " & !d57JobTitle
> >             .MoveNext
> >         Loop
> >     End With
> >
> >     With cboJobTitle
> >         .SetFocus
> >         .Text = cboJobTitle.ItemData(0)
> >     End With
> >
> >     rst.Close
> >
> >     Set rst = Nothing
> >     Set cnn = Nothing
> >End Sub
> >
> >'~~~~~~~~~~Stop~~~~~~~~~~
> >
> >If you feel like playing around with arrays a bit, the following code
>uses
> >the GetRows method of the recordset object which returns a
>two-dimensional
> >array.
> >The array's values are assigned to the combo boxes rowsource property.
> >
> >'~~~~~~~~~~Start~~~~~~~~~~
> >
> >Private Sub Form_Open(Cancel As Integer)
> >     Dim cnn As ADODB.Connection
> >     Dim rst As ADODB.Recordset
> >     Dim strList As String
> >     Dim strSQL As String
> >
> >     strSQL = "SELECT d57JobTitle FROM d57TblJobTitle " _
> >        & "ORDER BY d57JobTitle"
> >
> >     Set cnn = CurrentProject.Connection
> >
> >     Set rst = New ADODB.Recordset
> >     rst.Open strSQL, cnn, adOpenForwardOnly, adLockReadOnly
> >
> >     strList = BuildString(rst)
> >     With cboJobTitle
> >         .RowSource = strList
> >         .RowSourceType = "Value List"
> >         .SetFocus
> >         .Text = cboJobTitle.ItemData(0)
> >     End With
> >     rst.Close
> >
> >     Set rst = Nothing
> >     Set cnn = Nothing
> >End Sub
> >
> >Private Function BuildString(rst As ADODB.Recordset) As String
> >     Dim strReturn As String
> >     Dim varItems As Variant
> >     Dim x As Integer
> >     Dim y As Integer
> >
> >     rst.MoveFirst
> >
> >     varItems = rst.GetRows(10)
> >     For x = LBound(varItems, 2) To UBound(varItems, 2)
> >         For y = LBound(varItems, 1) To UBound(varItems, 1)
> >             strReturn = strReturn & varItems(y, x) & ";"
> >         Next y
> >     Next x
> >     BuildString = strReturn
> >End Function
> >
> >'~~~~~~~~~~Stop~~~~~~~~~~
> >
> >Best,
> >
> >Bob
> >
> >
> >
> >
> >
> >----- Original Message -----
> >From: "George Oro" <george@c...>
> >To: "Access" <access@p...>
> >Sent: Tuesday, October 22, 2002 10:52 AM
> >Subject: [access] RE: Populate (AddItem) in ComboBox
> >
> >
> > > Thanks John, but I got an error "Method or data member not found" and
> >the
> >AddItem is highlighted.
> > > This is what I did, I put the below code on my Form Load:
> > >
> > > Assuming cn is my ADODB Connection
> > >
> > >     'Populate Job Title ComboBox
> > >     Dim rsJobTitle as ADODB.Recordset
> > >     Dim strJobTitle As String
> > >     strJobTitle = "SELECT * FROM d57TblJobTitle ORDER BY d57JobTitle"
> > >
> > >     Set rsJobTitle = New ADODB.Recordset
> > >     rsJobTitle.CursorType = adOpenStatic
> > >     rsJobTitle.CursorLocation = adUseClient
> > >     rsJobTitle.LockType = adLockOptimistic
> > >     rsJobTitle.Open strJobTitle, cn
> > >
> > >     With rsJobTitle
> > >         .MoveFirst
> > >         Do Until .EOF
> > >             Me.txtJobTitle.AddItem !d57JobTitle
> > >             .MoveNext
> > >         Loop
> > >     End With
> > > ============================================
> > >
> > > Did I miss something?
> > > TIA,
> > > George
> > >
> > >
> > >
> > > -----Original Message-----
> > > From: John Pace [mailto:jpace@h...]
> > > Sent: Tuesday, October 22, 2002 6:02 PM
> > > To: Access
> > > Subject: [access] RE: Populate (AddItem) in ComboBox
> > >
> > >
> > > George,
> > >
> > > Do the following (I am assuming you are using a recordset call
> > > rstJobTitle).
> > > If you want to add all the records in the recordset to the combo box
>do
> > > the following:
> > >
> > > With rstJobTitle
> > >
> > > .MoveFirst
> > >
> > > Do Until .EOF
> > >
> > > ComboBox.AddItem !d57JobTitleID & " - " & !d57JobTitle
> > >
> > > .MoveNext
> > >
> > > Loop
> > >
> > > End With
> > >
> > > Hope that helps,
> > >
> > > John
> > >
> > > -----Original Message-----
> > > From: George Oro [mailto:george@c...]
> > > Sent: Tuesday, October 22, 2002 7:50 AM
> > > To: Access
> > > Subject: [access] Populate (AddItem) in ComboBox
> > >
> > > Thanks Bob for your idea and tips on my below post "Binding Fields".
> > >
> > > By the way, how can I populate or add item on my combo box using code?
> > > On my below post, I just add one ComboBox field "Job Title" and I have
>a
> > > table on my Access2K Back-end called d57TblJobTitle with
> > > the following fields d57JobTitleID & d57JobTitle.
> > >
> > > Any help is highly appreciated.
> > > TIA
> > > George ;D
> > >
> > > -----Original Message-----
> > > From: Bob Bedell [mailto:bobbedell15@m...]
> > > Sent: Monday, October 21, 2002 9:15 PM
> > > To: Access
> > > Subject: [access] Re: Binding Fields
> > >
> > >
> > > Hi George,
> > >
> > > That's how its done. Why are you using WithEvents in you declaration?
> > > You don't need it in this module. Only recommendation would be: in
>order
> > > to prevent your cursor from falling off the beginning or end of your
> > > recordset and producing weird error messages, have your navigation
> > > buttons check for the recordsets BOF and EOF properties. The following
> > > code also gives the user some halpful visual cues by enabling and
> > > disabling the appropriate navigation buttons.
> > >
> > > Private Sub cmdPrev_Click()
> > >
> > >     rsContacts.MovePrevious
> > >     txtContactsID.SetFocus
> > >     rsContacts.MovePrevious
> > >     If rsContacts.BOF Then
> > >         cmdPrev.Enabled = False
> > >     Else
> > >         cmdPrev.Enabled = True
> > >     End If
> > >     cmdNext.Enabled = True
> > >     rsContacts.MoveNext
> > >
> > >     BindAllFields
> > >
> > > End Sub
> > >
> > > Private Sub cmdNext_Click()
> > >     rsContacts.MoveNext
> > >     txtContactsID.SetFocus
> > >     rsContacts.MoveNext
> > >     If rsContacts.EOF Then
> > >         cmdNext.Enabled = False
> > >     Else
> > >         cmdNext.Enabled = True
> > >     End If
> > >     rsContacts.MovePrevious
> > >     cmdPrev.Enabled = True
> > >
> > >     BindAllFields
> > > End Sub
> > >
> > > Best,
> > >
> > > Bob
> > >
> > > >From: "George Oro" <george@c...>
> > > >Reply-To: "Access" <access@p...>
> > > >To: "Access" <access@p...>
> > > >Subject: [access] Binding Fields
> > > >Date: Mon, 21 Oct 2002 18:16:59 +0400
> > > >
> > > >Hi Guys,
> > > >
> > > >I just started connecting my database using ADODB coding, at present,
>I
> > > >just have 3 textbox fields and two cmdButton for test with
> > > >the following code:
> > > >QUESTION:
> > > >1) Is my connection OK? otherwise what is the best?
> > > >2) Is there any easiest way to bind my fields accordingly?
> > > >
> > > >Any help and idea is highly appreciated.
> > > >Cheers,
> > > >George
> > > >
> > > >MY CODE
> > > >----------
> > > >Option Compare Database
> > > >Option Explicit
> > > >Dim WithEvents rsContacts As ADODB.Recordset
> > > >----------
> > > >
> > > >Private Sub Form_Open(Cancel As Integer)
> > > >     'Database Connection
> > > >     Dim cn As ADODB.Connection
> > > >     Dim strCn As String
> > > >
> > > >     Set cn = New ADODB.Connection
> > > >     strCn = "Provider=Microsoft.Jet.OLEDB.4.0;Data
> > > >Source=C:\Database\MyVBapp\Communicator ComData.mdb;Persist Security
> > > >Info=False"
> > > >     cn.Open strCn
> > > >
> > > >     'Recordset Connection
> > > >     'Dim rsContacts As ADODB.Recordset
> > > >     Dim strRSContacts As String
> > > >
> > > >     Set rsContacts = New ADODB.Recordset
> > > >     strRSContacts = "SELECT * FROM m01TblContacts"
> > > >     rsContacts.Open strRSContacts, cn, adOpenStatic,
>adLockOptimistic
> > > >
> > > >     BindAllFields
> > > >
> > > >End Sub
> > > >----------------
> > > >Private Sub BindAllFields()
> > > >     With Me
> > > >         .txtContactsID = rsContacts("m01ContactsID")
> > > >         .txtFirstName = rsContacts("m01FirstName")
> > > >         .txtLastName = rsContacts("m01LastName")
> > > >     End With
> > > >End Sub
> > > >---------------
> > > >Private Sub cmdNext_Click()
> > > >On Error GoTo Err_cmdNext_Click
> > > >
> > > >
> > > >     rsContacts.MoveNext
> > > >     BindAllFields
> > > >
> > > >Exit_cmdNext_Click:
> > > >     Exit Sub
> > > >
> > > >Err_cmdNext_Click:
> > > >     MsgBox Err.Description
> > > >     Resume Exit_cmdNext_Click
> > > >
> > > >End Sub
> > > >----------------
> > > >Private Sub cmdPrev_Click()
> > > >On Error GoTo Err_cmdPrev_Click
> > > >
> > > >
> > > >     rsContacts.MovePrevious
> > > >     BindAllFields
> > > >
> > > >Exit_cmdPrev_Click:
> > > >     Exit Sub
> > > >
> > > >Err_cmdPrev_Click:
> > > >     MsgBox Err.Description
> > > >     Resume Exit_cmdPrev_Click
> > > >
> > > >End Sub
> > > >
> > > >
> > >
> > >
> > > _________________________________________________________________
> > > Choose an Internet access plan right for you -- try MSN!
> > > http://resourcecenter.msn.com/access/plans/default.asp
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> >
> >
> >
>
>
>_________________________________________________________________
>Surf the Web without missing calls! Get MSN Broadband.
>http://resourcecenter.msn.com/access/plans/freeactivation.asp
>
>
><< Coding.mdb >>


_________________________________________________________________
Surf the Web without missing calls! Get MSN Broadband.
http://resourcecenter.msn.com/access/plans/freeactivation.asp

Message #8 by braxis@b... on Wed, 23 Oct 2002 10:15:19 +0100 (BST)
George

I've been following this thread with much confusion, having never come across the 'AddItem' method for comboboxes before.

So, I tried using IntelliSense to get the AddItem method to come up on one of my combo boxes - no luck. I tried looking it up in the
Access help files - all I found after much struggling was code on how to add entries to a menu bar!

Finally, I wrote 'AddItem' in the VBA editor and pressed <F1> and up pops a window asking me which flavour of AddItem I'm
interested in. Excel has an AddItem method, so does the MS Flex Grid and finally so does the MS Forms COMBOBOX!!!

So, as far as I can see, the native Access combo box does not have an AddItem method, at least not in Access2K.

It should be fairly simple to code such a function though...

Brian

>  from:    George Oro <george@c...>
>  date:    Wed, 23 Oct 2002 05:46:40
>  to:      access@p...
>  subject: Re: [access] RE: Populate (AddItem) in ComboBox
> 
> Hi Bob,
> Thanks for your tips but still it didn't work, same error. By the way, I don't have any single table lying or linked in this
app.
> This is my Fron-end, and I'm accessing all my tables on my Back-end. Here below the current code on my Form_Open:
> 
> =====================================
> Private Sub Form_Open(Cancel As Integer)
>     'Database Connection
>     Dim cn As ADODB.Connection
>     Dim strCn As String
> 
>     Set cn = New ADODB.Connection
>     strCn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Database\MyVBapp\Communicator\ComData.mdb;Persist Security
Info=False"
>     cn.Open strCn
> 
>     'Recordset Connection
>     Dim strRSContacts As String
> 
>     Set rsContacts = New ADODB.Recordset
>     strRSContacts = "SELECT * FROM m01TblContacts"
>     rsContacts.Open strRSContacts, cn, adOpenStatic, adLockOptimistic
> 
>     'Populate Job Title ComboBox
>     Dim rsJobTitle As ADODB.Recordset
>     Dim strJobTitle As String
>     strJobTitle = "SELECT d57JobTitleID, d57JobTitle FROM d57TblJobTitle " _
>        & "ORDER BY d57JobTitleID"
> 
>     Set rsJobTitle = New ADODB.Recordset
>     rsJobTitle.Open strJobTitle, cn, adOpenForwardOnly, adLockReadOnly
> 
>     txtJobTitle.RowSourceType = "Value List"
> 
>     With rsJobTitle
>         .MoveFirst
>         Do Until .EOF
>             txtJobTitle.AddItem !d57JobTitleID & " - " & !d57JobTitle
>             .MoveNext
>         Loop
>     End With
> 
>     With txtJobTitle
>         .SetFocus
>         .Text = txtJobTitle.ItemData(0)
>     End With
> 
> end ================
> 
> -----Original Message-----
> From: Bob Bedell [mailto:bobbedell15@m...]
> Sent: Tuesday, October 22, 2002 9:02 PM
> To: Access
> Subject: [access] RE: Populate (AddItem) in ComboBox
> 
> 
> George,
> 
> Try the following. I added two things  to John's code. First, the line
> 
> cboJobTitle.RowSourceType = "Value List"
> 
> The AddItem method will only work if the control's rowsource type is a Value
> List.
> Second, the With block:
> 
>  With cboJobTitle
>         .SetFocus
>         .Text = cboJobTitle.ItemData(0)
>     End With
> 
> This will display the first value of the Value List in the combo boxes text
> area. Without
> this code, the combo will be populated, but nothing will be displayed by
> default.
> 
> '~~~~~~~~~~Start~~~~~~~~~~
> 
> Private Sub Form_Open(Cancel As Integer)
>     Dim cnn As ADODB.Connection
>     Dim rst As ADODB.Recordset
>     Dim strList As String
>     Dim strSQL As String
> 
>     strSQL = "SELECT d57JobTitleID, d57JobTitle FROM d57TblJobTitle " _
>        & "ORDER BY d57JobTitleID"
> 
>     Set cnn = CurrentProject.Connection
> 
>     Set rst = New ADODB.Recordset
>     rst.Open strSQL, cnn, adOpenForwardOnly, adLockReadOnly
> 
>     cboJobTitle.RowSourceType = "Value List"
> 
>     With rst
>         .MoveFirst
>         Do Until .EOF
>             cboJobTitle.AddItem !d57JobTitleID & " - " & !d57JobTitle
>             .MoveNext
>         Loop
>     End With
> 
>     With cboJobTitle
>         .SetFocus
>         .Text = cboJobTitle.ItemData(0)
>     End With
> 
>     rst.Close
> 
>     Set rst = Nothing
>     Set cnn = Nothing
> End Sub
> 
> '~~~~~~~~~~Stop~~~~~~~~~~
> 
> If you feel like playing around with arrays a bit, the following code uses
> the GetRows method of the recordset object which returns a two-dimensional
> array.
> The array's values are assigned to the combo boxes rowsource property.
> 
> '~~~~~~~~~~Start~~~~~~~~~~
> 
> Private Sub Form_Open(Cancel As Integer)
>     Dim cnn As ADODB.Connection
>     Dim rst As ADODB.Recordset
>     Dim strList As String
>     Dim strSQL As String
> 
>     strSQL = "SELECT d57JobTitle FROM d57TblJobTitle " _
>        & "ORDER BY d57JobTitle"
> 
>     Set cnn = CurrentProject.Connection
> 
>     Set rst = New ADODB.Recordset
>     rst.Open strSQL, cnn, adOpenForwardOnly, adLockReadOnly
> 
>     strList = BuildString(rst)
>     With cboJobTitle
>         .RowSource = strList
>         .RowSourceType = "Value List"
>         .SetFocus
>         .Text = cboJobTitle.ItemData(0)
>     End With
>     rst.Close
> 
>     Set rst = Nothing
>     Set cnn = Nothing
> End Sub
> 
> Private Function BuildString(rst As ADODB.Recordset) As String
>     Dim strReturn As String
>     Dim varItems As Variant
>     Dim x As Integer
>     Dim y As Integer
> 
>     rst.MoveFirst
> 
>     varItems = rst.GetRows(10)
>     For x = LBound(varItems, 2) To UBound(varItems, 2)
>         For y = LBound(varItems, 1) To UBound(varItems, 1)
>             strReturn = strReturn & varItems(y, x) & ";"
>         Next y
>     Next x
>     BuildString = strReturn
> End Function
> 
> '~~~~~~~~~~Stop~~~~~~~~~~
> 
> Best,
> 
> Bob
> 
> 
> 
> 
> 
> ----- Original Message -----
> From: "George Oro" <george@c...>
> To: "Access" <access@p...>
> Sent: Tuesday, October 22, 2002 10:52 AM
> Subject: [access] RE: Populate (AddItem) in ComboBox
> 
> 
> > Thanks John, but I got an error "Method or data member not found" and the
> AddItem is highlighted.
> > This is what I did, I put the below code on my Form Load:
> >
> > Assuming cn is my ADODB Connection
> >
> >     'Populate Job Title ComboBox
> >     Dim rsJobTitle as ADODB.Recordset
> >     Dim strJobTitle As String
> >     strJobTitle = "SELECT * FROM d57TblJobTitle ORDER BY d57JobTitle"
> >
> >     Set rsJobTitle = New ADODB.Recordset
> >     rsJobTitle.CursorType = adOpenStatic
> >     rsJobTitle.CursorLocation = adUseClient
> >     rsJobTitle.LockType = adLockOptimistic
> >     rsJobTitle.Open strJobTitle, cn
> >
> >     With rsJobTitle
> >         .MoveFirst
> >         Do Until .EOF
> >             Me.txtJobTitle.AddItem !d57JobTitle
> >             .MoveNext
> >         Loop
> >     End With
> > ============================================
> >
> > Did I miss something?
> > TIA,
> > George
> >
> >
> >
> > -----Original Message-----
> > From: John Pace [mailto:jpace@h...]
> > Sent: Tuesday, October 22, 2002 6:02 PM
> > To: Access
> > Subject: [access] RE: Populate (AddItem) in ComboBox
> >
> >
> > George,
> >
> > Do the following (I am assuming you are using a recordset call
> > rstJobTitle).
> > If you want to add all the records in the recordset to the combo box do
> > the following:
> >
> > With rstJobTitle
> >
> > .MoveFirst
> >
> > Do Until .EOF
> >
> > ComboBox.AddItem !d57JobTitleID & " - " & !d57JobTitle
> >
> > .MoveNext
> >
> > Loop
> >
> > End With
> >
> > Hope that helps,
> >
> > John
> >
> > -----Original Message-----
> > From: George Oro [mailto:george@c...]
> > Sent: Tuesday, October 22, 2002 7:50 AM
> > To: Access
> > Subject: [access] Populate (AddItem) in ComboBox
> >
> > Thanks Bob for your idea and tips on my below post "Binding Fields".
> >
> > By the way, how can I populate or add item on my combo box using code?
> > On my below post, I just add one ComboBox field "Job Title" and I have a
> > table on my Access2K Back-end called d57TblJobTitle with
> > the following fields d57JobTitleID & d57JobTitle.
> >
> > Any help is highly appreciated.
> > TIA
> > George ;D
> >
> > -----Original Message-----
> > From: Bob Bedell [mailto:bobbedell15@m...]
> > Sent: Monday, October 21, 2002 9:15 PM
> > To: Access
> > Subject: [access] Re: Binding Fields
> >
> >
> > Hi George,
> >
> > That's how its done. Why are you using WithEvents in you declaration?
> > You don't need it in this module. Only recommendation would be: in order
> > to prevent your cursor from falling off the beginning or end of your
> > recordset and producing weird error messages, have your navigation
> > buttons check for the recordsets BOF and EOF properties. The following
> > code also gives the user some halpful visual cues by enabling and
> > disabling the appropriate navigation buttons.
> >
> > Private Sub cmdPrev_Click()
> >
> >     rsContacts.MovePrevious
> >     txtContactsID.SetFocus
> >     rsContacts.MovePrevious
> >     If rsContacts.BOF Then
> >         cmdPrev.Enabled = False
> >     Else
> >         cmdPrev.Enabled = True
> >     End If
> >     cmdNext.Enabled = True
> >     rsContacts.MoveNext
> >
> >     BindAllFields
> >
> > End Sub
> >
> > Private Sub cmdNext_Click()
> >     rsContacts.MoveNext
> >     txtContactsID.SetFocus
> >     rsContacts.MoveNext
> >     If rsContacts.EOF Then
> >         cmdNext.Enabled = False
> >     Else
> >         cmdNext.Enabled = True
> >     End If
> >     rsContacts.MovePrevious
> >     cmdPrev.Enabled = True
> >
> >     BindAllFields
> > End Sub
> >
> > Best,
> >
> > Bob
> >
> > >From: "George Oro" <george@c...>
> > >Reply-To: "Access" <access@p...>
> > >To: "Access" <access@p...>
> > >Subject: [access] Binding Fields
> > >Date: Mon, 21 Oct 2002 18:16:59 +0400
> > >
> > >Hi Guys,
> > >
> > >I just started connecting my database using ADODB coding, at present, I
> > >just have 3 textbox fields and two cmdButton for test with
> > >the following code:
> > >QUESTION:
> > >1) Is my connection OK? otherwise what is the best?
> > >2) Is there any easiest way to bind my fields accordingly?
> > >
> > >Any help and idea is highly appreciated.
> > >Cheers,
> > >George
> > >
> > >MY CODE
> > >----------
> > >Option Compare Database
> > >Option Explicit
> > >Dim WithEvents rsContacts As ADODB.Recordset
> > >----------
> > >
> > >Private Sub Form_Open(Cancel As Integer)
> > >     'Database Connection
> > >     Dim cn As ADODB.Connection
> > >     Dim strCn As String
> > >
> > >     Set cn = New ADODB.Connection
> > >     strCn = "Provider=Microsoft.Jet.OLEDB.4.0;Data
> > >Source=C:\Database\MyVBapp\Communicator ComData.mdb;Persist Security
> > >Info=False"
> > >     cn.Open strCn
> > >
> > >     'Recordset Connection
> > >     'Dim rsContacts As ADODB.Recordset
> > >     Dim strRSContacts As String
> > >
> > >     Set rsContacts = New ADODB.Recordset
> > >     strRSContacts = "SELECT * FROM m01TblContacts"
> > >     rsContacts.Open strRSContacts, cn, adOpenStatic, adLockOptimistic
> > >
> > >     BindAllFields
> > >
> > >End Sub
> > >----------------
> > >Private Sub BindAllFields()
> > >     With Me
> > >         .txtContactsID = rsContacts("m01ContactsID")
> > >         .txtFirstName = rsContacts("m01FirstName")
> > >         .txtLastName = rsContacts("m01LastName")
> > >     End With
> > >End Sub
> > >---------------
> > >Private Sub cmdNext_Click()
> > >On Error GoTo Err_cmdNext_Click
> > >
> > >
> > >     rsContacts.MoveNext
> > >     BindAllFields
> > >
> > >Exit_cmdNext_Click:
> > >     Exit Sub
> > >
> > >Err_cmdNext_Click:
> > >     MsgBox Err.Description
> > >     Resume Exit_cmdNext_Click
> > >
> > >End Sub
> > >----------------
> > >Private Sub cmdPrev_Click()
> > >On Error GoTo Err_cmdPrev_Click
> > >
> > >
> > >     rsContacts.MovePrevious
> > >     BindAllFields
> > >
> > >Exit_cmdPrev_Click:
> > >     Exit Sub
> > >
> > >Err_cmdPrev_Click:
> > >     MsgBox Err.Description
> > >     Resume Exit_cmdPrev_Click
> > >
> > >End Sub
> > >
> > >
> >
> >
> > _________________________________________________________________
> > Choose an Internet access plan right for you -- try MSN!
> > http://resourcecenter.msn.com/access/plans/default.asp
> >
> >
> >
> >
> >
> >
> >
> >
> >
> 
> 
> 

Message #9 by "Helga Y. Anagnostopoulos" <helga@k...> on Wed, 23 Oct 2002 11:41:59 +0200
Hi Brian

If the intelisence does not work then you've got (usually) a mistake in the
name thus if the combo box name is cmbTest and you've typed cmbTet it will
not go on.

Furthermore the add item should not have more methods and things for
intellisence.

Just type:
with cmbTest
	.AddItem "Today"
      .AddItem "Tomorrow"
end with

or if you take it from a table:
while rs.eof = false
 with cmbTest
 	.AddItem rs!CustomerName
 end with
 rs.movenext
wend

Regards
Helga

NS: If you've typed cmbTest.Additem - place your mouse on additem and press
F1 - gives you good help.

-----Original Message-----
From: braxis@b... [mailto:braxis@b...]
Sent: Wednesday, October 23, 2002 11:15
To: Access
Subject: [access] RE: Populate (AddItem) in ComboBox


George

I've been following this thread with much confusion, having never come
across the 'AddItem' method for comboboxes before.

So, I tried using IntelliSense to get the AddItem method to come up on one
of my combo boxes - no luck. I tried looking it up in the Access help
files - all I found after much struggling was code on how to add entries to
a menu bar!

Finally, I wrote 'AddItem' in the VBA editor and pressed <F1> and up pops a
window asking me which flavour of AddItem I'm interested in. Excel has an
AddItem method, so does the MS Flex Grid and finally so does the MS Forms
COMBOBOX!!!

So, as far as I can see, the native Access combo box does not have an
AddItem method, at least not in Access2K.

It should be fairly simple to code such a function though...

Brian

>  from:    George Oro <george@c...>
>  date:    Wed, 23 Oct 2002 05:46:40
>  to:      access@p...
>  subject: Re: [access] RE: Populate (AddItem) in ComboBox
>
> Hi Bob,
> Thanks for your tips but still it didn't work, same error. By the way, I
don't have any single table lying or linked in this app.
> This is my Fron-end, and I'm accessing all my tables on my Back-end. Here
below the current code on my Form_Open:
>
> =====================================
> Private Sub Form_Open(Cancel As Integer)
>     'Database Connection
>     Dim cn As ADODB.Connection
>     Dim strCn As String
>
>     Set cn = New ADODB.Connection
>     strCn = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Database\MyVBapp\Communicator\ComData.mdb;Persist Security
Info=False"
>     cn.Open strCn
>
>     'Recordset Connection
>     Dim strRSContacts As String
>
>     Set rsContacts = New ADODB.Recordset
>     strRSContacts = "SELECT * FROM m01TblContacts"
>     rsContacts.Open strRSContacts, cn, adOpenStatic, adLockOptimistic
>
>     'Populate Job Title ComboBox
>     Dim rsJobTitle As ADODB.Recordset
>     Dim strJobTitle As String
>     strJobTitle = "SELECT d57JobTitleID, d57JobTitle FROM d57TblJobTitle "
_
>        & "ORDER BY d57JobTitleID"
>
>     Set rsJobTitle = New ADODB.Recordset
>     rsJobTitle.Open strJobTitle, cn, adOpenForwardOnly, adLockReadOnly
>
>     txtJobTitle.RowSourceType = "Value List"
>
>     With rsJobTitle
>         .MoveFirst
>         Do Until .EOF
>             txtJobTitle.AddItem !d57JobTitleID & " - " & !d57JobTitle
>             .MoveNext
>         Loop
>     End With
>
>     With txtJobTitle
>         .SetFocus
>         .Text = txtJobTitle.ItemData(0)
>     End With
>
> end ================
>
> -----Original Message-----
> From: Bob Bedell [mailto:bobbedell15@m...]
> Sent: Tuesday, October 22, 2002 9:02 PM
> To: Access
> Subject: [access] RE: Populate (AddItem) in ComboBox
>
>
> George,
>
> Try the following. I added two things  to John's code. First, the line
>
> cboJobTitle.RowSourceType = "Value List"
>
> The AddItem method will only work if the control's rowsource type is a
Value
> List.
> Second, the With block:
>
>  With cboJobTitle
>         .SetFocus
>         .Text = cboJobTitle.ItemData(0)
>     End With
>
> This will display the first value of the Value List in the combo boxes
text
> area. Without
> this code, the combo will be populated, but nothing will be displayed by
> default.
>
> '~~~~~~~~~~Start~~~~~~~~~~
>
> Private Sub Form_Open(Cancel As Integer)
>     Dim cnn As ADODB.Connection
>     Dim rst As ADODB.Recordset
>     Dim strList As String
>     Dim strSQL As String
>
>     strSQL = "SELECT d57JobTitleID, d57JobTitle FROM d57TblJobTitle " _
>        & "ORDER BY d57JobTitleID"
>
>     Set cnn = CurrentProject.Connection
>
>     Set rst = New ADODB.Recordset
>     rst.Open strSQL, cnn, adOpenForwardOnly, adLockReadOnly
>
>     cboJobTitle.RowSourceType = "Value List"
>
>     With rst
>         .MoveFirst
>         Do Until .EOF
>             cboJobTitle.AddItem !d57JobTitleID & " - " & !d57JobTitle
>             .MoveNext
>         Loop
>     End With
>
>     With cboJobTitle
>         .SetFocus
>         .Text = cboJobTitle.ItemData(0)
>     End With
>
>     rst.Close
>
>     Set rst = Nothing
>     Set cnn = Nothing
> End Sub
>
> '~~~~~~~~~~Stop~~~~~~~~~~
>
> If you feel like playing around with arrays a bit, the following code uses
> the GetRows method of the recordset object which returns a two-dimensional
> array.
> The array's values are assigned to the combo boxes rowsource property.
>
> '~~~~~~~~~~Start~~~~~~~~~~
>
> Private Sub Form_Open(Cancel As Integer)
>     Dim cnn As ADODB.Connection
>     Dim rst As ADODB.Recordset
>     Dim strList As String
>     Dim strSQL As String
>
>     strSQL = "SELECT d57JobTitle FROM d57TblJobTitle " _
>        & "ORDER BY d57JobTitle"
>
>     Set cnn = CurrentProject.Connection
>
>     Set rst = New ADODB.Recordset
>     rst.Open strSQL, cnn, adOpenForwardOnly, adLockReadOnly
>
>     strList = BuildString(rst)
>     With cboJobTitle
>         .RowSource = strList
>         .RowSourceType = "Value List"
>         .SetFocus
>         .Text = cboJobTitle.ItemData(0)
>     End With
>     rst.Close
>
>     Set rst = Nothing
>     Set cnn = Nothing
> End Sub
>
> Private Function BuildString(rst As ADODB.Recordset) As String
>     Dim strReturn As String
>     Dim varItems As Variant
>     Dim x As Integer
>     Dim y As Integer
>
>     rst.MoveFirst
>
>     varItems = rst.GetRows(10)
>     For x = LBound(varItems, 2) To UBound(varItems, 2)
>         For y = LBound(varItems, 1) To UBound(varItems, 1)
>             strReturn = strReturn & varItems(y, x) & ";"
>         Next y
>     Next x
>     BuildString = strReturn
> End Function
>
> '~~~~~~~~~~Stop~~~~~~~~~~
>
> Best,
>
> Bob
>
>
>
>
>
> ----- Original Message -----
> From: "George Oro" <george@c...>
> To: "Access" <access@p...>
> Sent: Tuesday, October 22, 2002 10:52 AM
> Subject: [access] RE: Populate (AddItem) in ComboBox
>
>
> > Thanks John, but I got an error "Method or data member not found" and
the
> AddItem is highlighted.
> > This is what I did, I put the below code on my Form Load:
> >
> > Assuming cn is my ADODB Connection
> >
> >     'Populate Job Title ComboBox
> >     Dim rsJobTitle as ADODB.Recordset
> >     Dim strJobTitle As String
> >     strJobTitle = "SELECT * FROM d57TblJobTitle ORDER BY d57JobTitle"
> >
> >     Set rsJobTitle = New ADODB.Recordset
> >     rsJobTitle.CursorType = adOpenStatic
> >     rsJobTitle.CursorLocation = adUseClient
> >     rsJobTitle.LockType = adLockOptimistic
> >     rsJobTitle.Open strJobTitle, cn
> >
> >     With rsJobTitle
> >         .MoveFirst
> >         Do Until .EOF
> >             Me.txtJobTitle.AddItem !d57JobTitle
> >             .MoveNext
> >         Loop
> >     End With
> > ============================================
> >
> > Did I miss something?
> > TIA,
> > George
> >
> >
> >
> > -----Original Message-----
> > From: John Pace [mailto:jpace@h...]
> > Sent: Tuesday, October 22, 2002 6:02 PM
> > To: Access
> > Subject: [access] RE: Populate (AddItem) in ComboBox
> >
> >
> > George,
> >
> > Do the following (I am assuming you are using a recordset call
> > rstJobTitle).
> > If you want to add all the records in the recordset to the combo box do
> > the following:
> >
> > With rstJobTitle
> >
> > .MoveFirst
> >
> > Do Until .EOF
> >
> > ComboBox.AddItem !d57JobTitleID & " - " & !d57JobTitle
> >
> > .MoveNext
> >
> > Loop
> >
> > End With
> >
> > Hope that helps,
> >
> > John
> >
> > -----Original Message-----
> > From: George Oro [mailto:george@c...]
> > Sent: Tuesday, October 22, 2002 7:50 AM
> > To: Access
> > Subject: [access] Populate (AddItem) in ComboBox
> >
> > Thanks Bob for your idea and tips on my below post "Binding Fields".
> >
> > By the way, how can I populate or add item on my combo box using code?
> > On my below post, I just add one ComboBox field "Job Title" and I have a
> > table on my Access2K Back-end called d57TblJobTitle with
> > the following fields d57JobTitleID & d57JobTitle.
> >
> > Any help is highly appreciated.
> > TIA
> > George ;D
> >
> > -----Original Message-----
> > From: Bob Bedell [mailto:bobbedell15@m...]
> > Sent: Monday, October 21, 2002 9:15 PM
> > To: Access
> > Subject: [access] Re: Binding Fields
> >
> >
> > Hi George,
> >
> > That's how its done. Why are you using WithEvents in you declaration?
> > You don't need it in this module. Only recommendation would be: in order
> > to prevent your cursor from falling off the beginning or end of your
> > recordset and producing weird error messages, have your navigation
> > buttons check for the recordsets BOF and EOF properties. The following
> > code also gives the user some halpful visual cues by enabling and
> > disabling the appropriate navigation buttons.
> >
> > Private Sub cmdPrev_Click()
> >
> >     rsContacts.MovePrevious
> >     txtContactsID.SetFocus
> >     rsContacts.MovePrevious
> >     If rsContacts.BOF Then
> >         cmdPrev.Enabled = False
> >     Else
> >         cmdPrev.Enabled = True
> >     End If
> >     cmdNext.Enabled = True
> >     rsContacts.MoveNext
> >
> >     BindAllFields
> >
> > End Sub
> >
> > Private Sub cmdNext_Click()
> >     rsContacts.MoveNext
> >     txtContactsID.SetFocus
> >     rsContacts.MoveNext
> >     If rsContacts.EOF Then
> >         cmdNext.Enabled = False
> >     Else
> >         cmdNext.Enabled = True
> >     End If
> >     rsContacts.MovePrevious
> >     cmdPrev.Enabled = True
> >
> >     BindAllFields
> > End Sub
> >
> > Best,
> >
> > Bob
> >
> > >From: "George Oro" <george@c...>
> > >Reply-To: "Access" <access@p...>
> > >To: "Access" <access@p...>
> > >Subject: [access] Binding Fields
> > >Date: Mon, 21 Oct 2002 18:16:59 +0400
> > >
> > >Hi Guys,
> > >
> > >I just started connecting my database using ADODB coding, at present, I
> > >just have 3 textbox fields and two cmdButton for test with
> > >the following code:
> > >QUESTION:
> > >1) Is my connection OK? otherwise what is the best?
> > >2) Is there any easiest way to bind my fields accordingly?
> > >
> > >Any help and idea is highly appreciated.
> > >Cheers,
> > >George
> > >
> > >MY CODE
> > >----------
> > >Option Compare Database
> > >Option Explicit
> > >Dim WithEvents rsContacts As ADODB.Recordset
> > >----------
> > >
> > >Private Sub Form_Open(Cancel As Integer)
> > >     'Database Connection
> > >     Dim cn As ADODB.Connection
> > >     Dim strCn As String
> > >
> > >     Set cn = New ADODB.Connection
> > >     strCn = "Provider=Microsoft.Jet.OLEDB.4.0;Data
> > >Source=C:\Database\MyVBapp\Communicator ComData.mdb;Persist Security
> > >Info=False"
> > >     cn.Open strCn
> > >
> > >     'Recordset Connection
> > >     'Dim rsContacts As ADODB.Recordset
> > >     Dim strRSContacts As String
> > >
> > >     Set rsContacts = New ADODB.Recordset
> > >     strRSContacts = "SELECT * FROM m01TblContacts"
> > >     rsContacts.Open strRSContacts, cn, adOpenStatic, adLockOptimistic
> > >
> > >     BindAllFields
> > >
> > >End Sub
> > >----------------
> > >Private Sub BindAllFields()
> > >     With Me
> > >         .txtContactsID = rsContacts("m01ContactsID")
> > >         .txtFirstName = rsContacts("m01FirstName")
> > >         .txtLastName = rsContacts("m01LastName")
> > >     End With
> > >End Sub
> > >---------------
> > >Private Sub cmdNext_Click()
> > >On Error GoTo Err_cmdNext_Click
> > >
> > >
> > >     rsContacts.MoveNext
> > >     BindAllFields
> > >
> > >Exit_cmdNext_Click:
> > >     Exit Sub
> > >
> > >Err_cmdNext_Click:
> > >     MsgBox Err.Description
> > >     Resume Exit_cmdNext_Click
> > >
> > >End Sub
> > >----------------
> > >Private Sub cmdPrev_Click()
> > >On Error GoTo Err_cmdPrev_Click
> > >
> > >
> > >     rsContacts.MovePrevious
> > >     BindAllFields
> > >
> > >Exit_cmdPrev_Click:
> > >     Exit Sub
> > >
> > >Err_cmdPrev_Click:
> > >     MsgBox Err.Description
> > >     Resume Exit_cmdPrev_Click
> > >
> > >End Sub
> > >
> > >
> >
> >
> > _________________________________________________________________
> > Choose an Internet access plan right for you -- try MSN!
> > http://resourcecenter.msn.com/access/plans/default.asp
> >
> >
> >
> >
> >
> >
> >
> >
> >
>
>
>



Message #10 by braxis@b... on Wed, 23 Oct 2002 12:04:04 +0100 (BST)
Helga

No, my version of Access (Access 2000 SR-1) just doesn't have an AddItem method for native combobox controls.

...I've just gone and looked at the MS Knowledgebase, and guess what? AddItem is a new method introduced in Access XP!

Quote from KDB Q280372

'This article shows you how to use the new AddItem method in Microsoft Access to fill a list box or a combo box with the names of
database objects.'

So that explains mine, and George's, problem.

Brian

>  from:    "Helga Y. Anagnostopoulos" <helga@k...>
>  date:    Wed, 23 Oct 2002 10:41:59
>  to:      access@p...
>  subject: Re: [access] RE: Populate (AddItem) in ComboBox
> 
> Hi Brian
> 
> If the intelisence does not work then you've got (usually) a mistake in the
> name thus if the combo box name is cmbTest and you've typed cmbTet it will
> not go on.
> 
> Furthermore the add item should not have more methods and things for
> intellisence.
> 
> Just type:
> with cmbTest
> 	.AddItem "Today"
>       .AddItem "Tomorrow"
> end with
> 
> or if you take it from a table:
> while rs.eof = false
>  with cmbTest
>  	.AddItem rs!CustomerName
>  end with
>  rs.movenext
> wend
> 
> Regards
> Helga
> 
> NS: If you've typed cmbTest.Additem - place your mouse on additem and press
> F1 - gives you good help.
> 
> -----Original Message-----
> From: braxis@b... [mailto:braxis@b...]
> Sent: Wednesday, October 23, 2002 11:15
> To: Access
> Subject: [access] RE: Populate (AddItem) in ComboBox
> 
> 
> George
> 
> I've been following this thread with much confusion, having never come
> across the 'AddItem' method for comboboxes before.
> 
> So, I tried using IntelliSense to get the AddItem method to come up on one
> of my combo boxes - no luck. I tried looking it up in the Access help
> files - all I found after much struggling was code on how to add entries to
> a menu bar!
> 
> Finally, I wrote 'AddItem' in the VBA editor and pressed <F1> and up pops a
> window asking me which flavour of AddItem I'm interested in. Excel has an
> AddItem method, so does the MS Flex Grid and finally so does the MS Forms
> COMBOBOX!!!
> 
> So, as far as I can see, the native Access combo box does not have an
> AddItem method, at least not in Access2K.
> 
> It should be fairly simple to code such a function though...
> 
> Brian
> 
> >  from:    George Oro <george@c...>
> >  date:    Wed, 23 Oct 2002 05:46:40
> >  to:      access@p...
> >  subject: Re: [access] RE: Populate (AddItem) in ComboBox
> >
> > Hi Bob,
> > Thanks for your tips but still it didn't work, same error. By the way, I
> don't have any single table lying or linked in this app.
> > This is my Fron-end, and I'm accessing all my tables on my Back-end. Here
> below the current code on my Form_Open:
> >
> > =====================================
> > Private Sub Form_Open(Cancel As Integer)
> >     'Database Connection
> >     Dim cn As ADODB.Connection
> >     Dim strCn As String
> >
> >     Set cn = New ADODB.Connection
> >     strCn = "Provider=Microsoft.Jet.OLEDB.4.0;Data
> Source=C:\Database\MyVBapp\Communicator\ComData.mdb;Persist Security
> Info=False"
> >     cn.Open strCn
> >
> >     'Recordset Connection
> >     Dim strRSContacts As String
> >
> >     Set rsContacts = New ADODB.Recordset
> >     strRSContacts = "SELECT * FROM m01TblContacts"
> >     rsContacts.Open strRSContacts, cn, adOpenStatic, adLockOptimistic
> >
> >     'Populate Job Title ComboBox
> >     Dim rsJobTitle As ADODB.Recordset
> >     Dim strJobTitle As String
> >     strJobTitle = "SELECT d57JobTitleID, d57JobTitle FROM d57TblJobTitle "
> _
> >        & "ORDER BY d57JobTitleID"
> >
> >     Set rsJobTitle = New ADODB.Recordset
> >     rsJobTitle.Open strJobTitle, cn, adOpenForwardOnly, adLockReadOnly
> >
> >     txtJobTitle.RowSourceType = "Value List"
> >
> >     With rsJobTitle
> >         .MoveFirst
> >         Do Until .EOF
> >             txtJobTitle.AddItem !d57JobTitleID & " - " & !d57JobTitle
> >             .MoveNext
> >         Loop
> >     End With
> >
> >     With txtJobTitle
> >         .SetFocus
> >         .Text = txtJobTitle.ItemData(0)
> >     End With
> >
> > end ================
> >
> > -----Original Message-----
> > From: Bob Bedell [mailto:bobbedell15@m...]
> > Sent: Tuesday, October 22, 2002 9:02 PM
> > To: Access
> > Subject: [access] RE: Populate (AddItem) in ComboBox
> >
> >
> > George,
> >
> > Try the following. I added two things  to John's code. First, the line
> >
> > cboJobTitle.RowSourceType = "Value List"
> >
> > The AddItem method will only work if the control's rowsource type is a
> Value
> > List.
> > Second, the With block:
> >
> >  With cboJobTitle
> >         .SetFocus
> >         .Text = cboJobTitle.ItemData(0)
> >     End With
> >
> > This will display the first value of the Value List in the combo boxes
> text
> > area. Without
> > this code, the combo will be populated, but nothing will be displayed by
> > default.
> >
> > '~~~~~~~~~~Start~~~~~~~~~~
> >
> > Private Sub Form_Open(Cancel As Integer)
> >     Dim cnn As ADODB.Connection
> >     Dim rst As ADODB.Recordset
> >     Dim strList As String
> >     Dim strSQL As String
> >
> >     strSQL = "SELECT d57JobTitleID, d57JobTitle FROM d57TblJobTitle " _
> >        & "ORDER BY d57JobTitleID"
> >
> >     Set cnn = CurrentProject.Connection
> >
> >     Set rst = New ADODB.Recordset
> >     rst.Open strSQL, cnn, adOpenForwardOnly, adLockReadOnly
> >
> >     cboJobTitle.RowSourceType = "Value List"
> >
> >     With rst
> >         .MoveFirst
> >         Do Until .EOF
> >             cboJobTitle.AddItem !d57JobTitleID & " - " & !d57JobTitle
> >             .MoveNext
> >         Loop
> >     End With
> >
> >     With cboJobTitle
> >         .SetFocus
> >         .Text = cboJobTitle.ItemData(0)
> >     End With
> >
> >     rst.Close
> >
> >     Set rst = Nothing
> >     Set cnn = Nothing
> > End Sub
> >
> > '~~~~~~~~~~Stop~~~~~~~~~~
> >
> > If you feel like playing around with arrays a bit, the following code uses
> > the GetRows method of the recordset object which returns a two-dimensional
> > array.
> > The array's values are assigned to the combo boxes rowsource property.
> >
> > '~~~~~~~~~~Start~~~~~~~~~~
> >
> > Private Sub Form_Open(Cancel As Integer)
> >     Dim cnn As ADODB.Connection
> >     Dim rst As ADODB.Recordset
> >     Dim strList As String
> >     Dim strSQL As String
> >
> >     strSQL = "SELECT d57JobTitle FROM d57TblJobTitle " _
> >        & "ORDER BY d57JobTitle"
> >
> >     Set cnn = CurrentProject.Connection
> >
> >     Set rst = New ADODB.Recordset
> >     rst.Open strSQL, cnn, adOpenForwardOnly, adLockReadOnly
> >
> >     strList = BuildString(rst)
> >     With cboJobTitle
> >         .RowSource = strList
> >         .RowSourceType = "Value List"
> >         .SetFocus
> >         .Text = cboJobTitle.ItemData(0)
> >     End With
> >     rst.Close
> >
> >     Set rst = Nothing
> >     Set cnn = Nothing
> > End Sub
> >
> > Private Function BuildString(rst As ADODB.Recordset) As String
> >     Dim strReturn As String
> >     Dim varItems As Variant
> >     Dim x As Integer
> >     Dim y As Integer
> >
> >     rst.MoveFirst
> >
> >     varItems = rst.GetRows(10)
> >     For x = LBound(varItems, 2) To UBound(varItems, 2)
> >         For y = LBound(varItems, 1) To UBound(varItems, 1)
> >             strReturn = strReturn & varItems(y, x) & ";"
> >         Next y
> >     Next x
> >     BuildString = strReturn
> > End Function
> >
> > '~~~~~~~~~~Stop~~~~~~~~~~
> >
> > Best,
> >
> > Bob
> >
> >
> >
> >
> >
> > ----- Original Message -----
> > From: "George Oro" <george@c...>
> > To: "Access" <access@p...>
> > Sent: Tuesday, October 22, 2002 10:52 AM
> > Subject: [access] RE: Populate (AddItem) in ComboBox
> >
> >
> > > Thanks John, but I got an error "Method or data member not found" and
> the
> > AddItem is highlighted.
> > > This is what I did, I put the below code on my Form Load:
> > >
> > > Assuming cn is my ADODB Connection
> > >
> > >     'Populate Job Title ComboBox
> > >     Dim rsJobTitle as ADODB.Recordset
> > >     Dim strJobTitle As String
> > >     strJobTitle = "SELECT * FROM d57TblJobTitle ORDER BY d57JobTitle"
> > >
> > >     Set rsJobTitle = New ADODB.Recordset
> > >     rsJobTitle.CursorType = adOpenStatic
> > >     rsJobTitle.CursorLocation = adUseClient
> > >     rsJobTitle.LockType = adLockOptimistic
> > >     rsJobTitle.Open strJobTitle, cn
> > >
> > >     With rsJobTitle
> > >         .MoveFirst
> > >         Do Until .EOF
> > >             Me.txtJobTitle.AddItem !d57JobTitle
> > >             .MoveNext
> > >         Loop
> > >     End With
> > > ============================================
> > >
> > > Did I miss something?
> > > TIA,
> > > George
> > >
> > >
> > >
> > > -----Original Message-----
> > > From: John