Run-time error '3265' - Item cannot be found in the collection corresponding to the requested name or ordinal.

rsbuzatto

Board Regular
Joined
Mar 19, 2012
Messages
70
Hello everybody,

I'm developing a VBA application to control some datas from my workmates. I'm using Excel 2007 for everything, however, I need to consolidate those datas into one simples database.

My workmates are gonna fill some userforms and those form datas are transferred to a new sheet in the same workbook. What I need to do now is:

- When the user click in the SAVE BUTTON, those datas will be transferred to the sheet as I'm doing now AND, I need the same datas transferred to an Access 2007 (.accdb) file.

Nevertheless, I've got a problem in my database code.

Take a look below!

Code:
1. Sub Transf_BD(Codigo As Variant)
2.    
3.    Dim cnn As ADODB.Connection
4.    Dim rst As ADODB.Recordset
5.    
6.    'Abre a conexão com o Banco de Dados
7.    Set cnn = New ADODB.Connection
8.    
9.    cnn.Open "Provider=Microsoft.Ace.OLEDB.12.0; Persist Security Info = False;" & _
10.                "Data Source=C:\BD_Ideia.accdb;"
11.
12.    'Definir o Recordset
13.    Set rst = New ADODB.Recordset
14.    rst.CursorLocation = adUseServer
15.    
16.    'Abre a tabela do Banco de Dados
17.    rst.Open Source:="tblTransfer", _
18.                      ActiveConnection:=cnn, _
19.                      CursorType:=adOpenDynamic, _
20.                      LockType:=adLockOptimistic, _
21.                      Options:=adCmdTable
22.    
23.    'Adiciona um Registro
24.    rst.AddNew
25.    
26.    'Configura os valores para os campos.
27.    'Os campos são passados do userform.
28.    rst("Codigo") = "TEST"
29.
30.    'Escreva os valores para este registro
31.    rst.Update
32.    
33.    'Fechar
34.    rst.Close
35.    cnn.Close
36    
37.End Sub

In the end of my SAVE FUNCTION I wrote:

Code:
Transf_BD (Codigo)

When I run this code, I've got a problem: Run-time error '3265' Item cannot be found in the collection corresponding to the requested name or ordinal. in Line 28.

Please, can anyone help me with this error? I really need to fix it as soon as I can! :(

EDITING: I'm doing that with only Codigo as Variant (Code as Variant, in English) as a parameter to test my macro. When everything's running clearly, I'll insert other parameters for all of my userforms...

Cheers folks!
 
Last edited:
that bit is part of the sub that then calls Transf_BD and passes the pm argument to it.
 
Upvote 0

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
If I do such a thing... I'll get an error in Transf_Bd pm...

So... that's why I'm asking you...

Where should I write or what I'm doing wrong with my code..? :\

I sent a Private Mess with my Sub Transf_BD ... if can have a look... :confused:
 
Upvote 0
Please do not PM parts of questions - it prevents anyone else benefitting from this thread later.
Please post the code here and I will take a look when I get home later.
 
Upvote 0
Well...

Take a look at what I've done...

Code:
'Main Sub: Execute my Arguments to pass 'em to my Insertion Sub
Sub Executa_Transf()
    
Dim pm As Parameters
With pm
     .TituloIdeia = tbTitulo.Value
     (and so on...)
End With

Inserir_BD pm

End Sub

Code:
'Insertion Sub: Insert new data into my Database
Sub Inserir_BD(pm As Parameters)

Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
    
'Abre a conexão com o Banco de Dados
Set cnn = New ADODB.Connection
    
cnn.Open "Provider=Microsoft.Ace.OLEDB.12.0; Persist Security Info = False;" & _
            "Data Source=C:\BD_Ideia.accdb;"
    
'Definir o Recordset
Set rst = New ADODB.Recordset
rst.CursorLocation = adUseServer
    
'Abre a tabela do Banco de Dados
rst.Open Source:="tblTransfer", _
                  ActiveConnection:=cnn, _
                  CursorType:=adOpenDynamic, _
                  LockType:=adLockOptimistic, _
                  Options:=adCmdTable
    
'Adiciona um Registro
rst.AddNew

rst("Título da Idéia") = pm.TituloIdeia
(and so on...)

rst.Update
rst.Close
cnn.Close

End Sub

Into my SAVE BUTTON CODE I put:
Code:
Executa_Transf

Nevertheless, its not running!
The error is in line .TituloIdeia = tbTitulo.Value (Sub Executa_Transf)... :(

Thanks for all your help man...
 
Upvote 0
what is the error?
 
Upvote 0
is the code in the form with the textbox on it?
 
Upvote 0
Just thought - choose a different name for your UDT - Parameters is an ADO object, so not a good name.
 
Upvote 0
Just thought - choose a different name for your UDT - Parameters is an ADO object, so not a good name.

What do you mean... should I change all names of my 18 parameters?

Yet, do you have any tip of what kind of name should I use?


Thanks!
 
Upvote 0

Forum statistics

Threads
1,215,581
Messages
6,125,656
Members
449,247
Latest member
wingedshoes

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top