Using value of a function with left()

habiler

Registered User.
Local time
Today, 22:58
Joined
Aug 10, 2014
Messages
70
Good morning to the community


I would like to use the value of Numchaine in rematricule but I have an error message "non optional argument".

Someone would have an idea where the mistake came from.

Code:
....
 
LeMatricule = Left(rst!NomNameMatrK,1, NumChaine)
 
............
 
Public Function NumChaine(chaine) As String
Dim A As String
 A = InStrRev(chaine, "-") - 2
NumChaine = A
 
End Function
 
NumChaine is a function that return string.
function Left only needs two arrguments:

Left(string, lengthN)
 
And... NumChaine needs an argument for chaine. Hence, the error.
 
I have the same error with

Code:
LeMatricule = Left(rst!NomNameMatrK, NumChaine)

I modify too :

Code:
Function NumChaine(chaine) As Long

 NumChaine = InStrRev(chaine, "-") - 2
  

End Function
 
I have the same error with

Code:
LeMatricule = Left(rst!NomNameMatrK, NumChaine)
I modify too :

Code:
Function NumChaine(chaine) As Long

 NumChaine = InStrRev(chaine, "-") - 2
  

End Function
Hi. We're not sure what you're trying to do, but like I said earlier, the function NumChaine() requires/expects one argument called chaine. So, your code should, at least, look something like this:
Code:
LeMatricule = Left(rst!NomNameMatrK, NumChaine([COLOR=Red][B]SomethingGoesInHere[/B][/COLOR]))
 
You might want to start inspecting the contents of the variables/fields in Debug to see what it is 'actually' doing?:confused:

I have the same error with

Code:
LeMatricule = Left(rst!NomNameMatrK, NumChaine)

I modify too :

Code:
Function NumChaine(chaine) As Long

 NumChaine = InStrRev(chaine, "-") - 2
  

End Function
 
The value of Numchain is Ok in the debugging area (and the function zone)
but empty in the main code
 
The value of Numchain is Ok in the debugging area (and the function zone)
but empty in the main code
Hi. Rather than us try to analyze your code, can you tell us, using plain words, what you're trying to accomplish? Also, are you able to post a demo version of your db? Thanks.
 
Just to be absolutely clear, your "non optional argument" problem is highlighted below.

Code:
LeMatricule = Left(rst!NomNameMatrK,1, [COLOR="Red"]NumChaine[/COLOR])
 
............
 
Public Function [COLOR="Red"]NumChaine[/COLOR]([COLOR="YellowGreen"]chaine[/COLOR]) [COLOR="RoyalBlue"]As String[/COLOR]
Dim A [COLOR="DarkOrchid"]As String[/COLOR]
 [COLOR="Sienna"]A = InStrRev(chaine, "-") - 2[/COLOR]
NumChaine = A
 
End Function

The non-optional argument is Chaine, as in NumChaine(Chaine). That function could be used in another function... BUT keeping on with this analysis, NumChaine returns a string which you promptly use in a context that requires a number, not a string - the length argument of Left(string,number). And besides that, inside the function you define A as a string but InStrRev returns a number (representing a position within a string). So you have several errors of incorrect data type and that is probably adding to a whole bucket full of confusion.
 
Doc,
It was a string being returned initially, but then changed to a number, but the o/p is still not passing the argument to the function and cannot seem to grasp this?
 

Users who are viewing this thread

Back
Top Bottom