VBA Access execution problem of a button

darkspoilt Posted messages 76 Registration date   Status Member Last intervention   -  
sncf Posted messages 122 Status Member -
Hello,
I created a temporary code to test my function on click when filling out a form

and it has an error when I click the button it writes to me

"The expression on click entered as a parameter for the event type property is causing a defined user type error.
The result of the expression is not the name of a macro, the name of a user-defined function, or [Event procedure]

An error may have occurred while evaluating a function, an event, or a macro."

My button is configured for event procedure
If someone sees the error, I thank them in advance

Sub Commande0_Click() Dim l As Integer l = Ligne() DoCmd.TransferSpreadsheet acImport, , CA, "D:\Eric\dossier_projets\TDB\Chiffres-Affaires\a-Activité paiement porteurs CA an2007.xls", 0, "K" & i End Sub Public Function Ligne() As Integer Public AppExcel As Excel.Application Private wbFile As Excel.Workbook Public i As Integer Set AppExcel = CreateObject("Excel.Application") ' Opening excel If Not AppExcel Is Nothing Then Set wbFile = AppExcel.Workbooks.Open("c:\toto.xls", False, True) 'Opening the workbook If Not wbFile Is Nothing Then Do While Cells(i, 1).Text <> "TOTAL" i = i + 1 Loop wbFile.Close AppExcel.Application.Quit Set AppExcel = Nothing End If End If End Function 
Configuration: Windows XP Internet Explorer 6.0

6 answers

xjl Posted messages 232 Status Member 183
 
Hello, it might come from there:

Public Function Line() As Integer

Try Integer instead... ;-)
0
darkspoilt Posted messages 76 Registration date   Status Member Last intervention   1
 
Merci maintenant j'ai un problème avec mon

 DoCmd.TransferSpreadsheet acImport, , "CA", Chiffre, 0, "K" & i
0
sncf Posted messages 122 Status Member 14
 
Good evening
In your sub, what is the i?
--
Pascal
How complicated it is when we search, how simple it is when we have found it
0
darkspoilt Posted messages 76 Registration date   Status Member Last intervention   1
 
The i represents a variable containing the number of the row of the cell I want to import.
0
darkspoilt Posted messages 76 Registration date   Status Member Last intervention   1
 
Yes, it's resolved, but how could I import it into the correct field of my table?
0
sncf Posted messages 122 Status Member 14
 
Good evening
The line number to be imported must be somewhere; in that case, it's enough to retrieve it (possibly by having placed it beforehand in an invisible control on your form)
--
Pascal
How complicated it is when we search, how simple it is when we've found it.
0