Help!Error 3265, loading fr cbo box to combo box and then to txt b

M

mju

Please i need serious help!!
I am trying to retrieve all the contact names for specific company into a
combox box whenever the user selects the company's name from a combo box.
I keep getting error: "Run-time error '3265': Item cannot be found in the
collection
corresponding to the requested name or ordinal" error centered on:
Me.Contact_NameCMB.Value = rs.feilds("RdcRetailerContactName")
Also, how do i program it to display contact information in different text
boxes whenever a contact name is selected?

Summary:
1) Load retailer's name into a combo box. (works fine)
2) Load all contact names for that retailer into another combo box whenever
a retailer name is selected from step 1
3) Dislay contact informations into different text boxes whenever name is
selected from step 2. I dont have anything on step 3 yet.

Your help will be greatly appreciated!!!!!!!
Thanks alot!!!!!!!!!!!!!!!!!!!!

Step 2
' THIS IS WHERE THE PROBLEM LIES:frustrated:
Private Sub Contact_NameCMB_AfterUpdate()
Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sSQL As String, strConn
Dim ContactName As String
Dim contact_name As String
Dim contact As String

'strConn = " C:\Documents and
Settings\spring-004\Desktop\SPRING-CSS-DB_BE.mdb"
strConn = " C:\Documents and Settings\Desktop\Retailer-DB_BE.mdb"
Set cnn = New ADODB.Connection
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & strConn

Retailer_Name = Me.RetailerName.Value
sSQL = "SELECT [tblRetailerDocumentContacts.RdcRetailerContactName] FROM
tblRetailerDocumentContacts WHERE
[tblRetailerDocumentContacts.RdcRetailerContactName]='" & Retailer_Name & "';"
Set rs = New ADODB.Recordset
rs.Open sSQL, cnn, adOpenStatic, adLockOptimistic

'If rs.BOF And rs.EOF Then
'Set rs = New ADODB.Recordset
Do While rs.EOF = False
Me.Contact_NameCMB.Value = rs.feilds("RdcRetailerContactName")
rs.MoveNext
Loop

' If rs.EOF = False Then
'Me.Text76.Value = rs(rs!RdcRetailerName)
' Else
' Me.Contact_NameCMB.Value = ""
'
' End If



rs.Close
Set rs = Nothing
'Set rs = rs.NextRecordset
End Sub

'THIS WORKS FINE. IT LOADS DATA INTO THE COMBO BOX
Private Sub Form_Load()

On Error GoTo UserForm_Initialize_Err
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim con As String

strConn = " C:\Documents and Settings\Desktop\Retailer-DB_BE.mdb"
Set cnn = New ADODB.Connection
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & strConn


rst.Open "SELECT DISTINCT [tblRetailerDocumentContacts.RdcRetailerName]
FROM tblRetailerDocumentContacts ORDER BY
[tblRetailerDocumentContacts.RdcRetailerName];", _
cnn, adOpenStatic
rst.MoveFirst
With Me.RetailerName
Me.Clear
Do
.AddItem rst![tblRetailerDocumentContacts.RdcRetailerName]
rst.MoveNext
Loop Until rst.EOF
End With
UserForm_Initialize_Exit:
On Error Resume Next
rst.Close
cnn.Close
Set rst = Nothing
Set cnn = Nothing
Exit Sub
UserForm_Initialize_Err:
MsgBox Err.Number & vbCrLf & Err.Description, vbCritical, "Error!"
Resume UserForm_Initialize_Exit

end sub
 
D

Douglas J. Steele

You've misspelled Fields. Try

Me.Contact_NameCMB.Value = rs.Fields("RdcRetailerContactName")

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


mju said:
Please i need serious help!!
I am trying to retrieve all the contact names for specific company into a
combox box whenever the user selects the company's name from a combo box.
I keep getting error: "Run-time error '3265': Item cannot be found in the
collection
corresponding to the requested name or ordinal" error centered on:
Me.Contact_NameCMB.Value = rs.feilds("RdcRetailerContactName")
Also, how do i program it to display contact information in different text
boxes whenever a contact name is selected?

Summary:
1) Load retailer's name into a combo box. (works fine)
2) Load all contact names for that retailer into another combo box
whenever
a retailer name is selected from step 1
3) Dislay contact informations into different text boxes whenever name is
selected from step 2. I dont have anything on step 3 yet.

Your help will be greatly appreciated!!!!!!!
Thanks alot!!!!!!!!!!!!!!!!!!!!

Step 2
' THIS IS WHERE THE PROBLEM LIES:frustrated:
Private Sub Contact_NameCMB_AfterUpdate()
Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sSQL As String, strConn
Dim ContactName As String
Dim contact_name As String
Dim contact As String

'strConn = " C:\Documents and
Settings\spring-004\Desktop\SPRING-CSS-DB_BE.mdb"
strConn = " C:\Documents and Settings\Desktop\Retailer-DB_BE.mdb"
Set cnn = New ADODB.Connection
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & strConn

Retailer_Name = Me.RetailerName.Value
sSQL = "SELECT [tblRetailerDocumentContacts.RdcRetailerContactName] FROM
tblRetailerDocumentContacts WHERE
[tblRetailerDocumentContacts.RdcRetailerContactName]='" & Retailer_Name &
"';"
Set rs = New ADODB.Recordset
rs.Open sSQL, cnn, adOpenStatic, adLockOptimistic

'If rs.BOF And rs.EOF Then
'Set rs = New ADODB.Recordset
Do While rs.EOF = False
Me.Contact_NameCMB.Value = rs.feilds("RdcRetailerContactName")
rs.MoveNext
Loop

' If rs.EOF = False Then
'Me.Text76.Value = rs(rs!RdcRetailerName)
' Else
' Me.Contact_NameCMB.Value = ""
'
' End If



rs.Close
Set rs = Nothing
'Set rs = rs.NextRecordset
End Sub

'THIS WORKS FINE. IT LOADS DATA INTO THE COMBO BOX
Private Sub Form_Load()

On Error GoTo UserForm_Initialize_Err
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim con As String

strConn = " C:\Documents and Settings\Desktop\Retailer-DB_BE.mdb"
Set cnn = New ADODB.Connection
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & strConn


rst.Open "SELECT DISTINCT [tblRetailerDocumentContacts.RdcRetailerName]
FROM tblRetailerDocumentContacts ORDER BY
[tblRetailerDocumentContacts.RdcRetailerName];", _
cnn, adOpenStatic
rst.MoveFirst
With Me.RetailerName
Me.Clear
Do
.AddItem rst![tblRetailerDocumentContacts.RdcRetailerName]
rst.MoveNext
Loop Until rst.EOF
End With
UserForm_Initialize_Exit:
On Error Resume Next
rst.Close
cnn.Close
Set rst = Nothing
Set cnn = Nothing
Exit Sub
UserForm_Initialize_Err:
MsgBox Err.Number & vbCrLf & Err.Description, vbCritical, "Error!"
Resume UserForm_Initialize_Exit

end sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top