Re: Function returns Datatype Mismatch

Tech-Archive recommends: Fix windows errors by optimizing your registry



Thanks for your help that works great.

Sincerely,
David Greer

"Dirk Goldgar" wrote:

> "davidg2356" <davidg2356@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
> news:F52C4F53-13C3-4697-AA7B-128F2F8FEA03@xxxxxxxxxxxxx
> > Hi,
> >
> > I am attempting to split a part an account code to extract part of
> > it, and some great people here have given me some code to aid in this
> > endeavor. (I have now read a few chapters about Visual Basic),
> > however I am encountering the following error:
> >
> > Run-time Error '13':
> > Type Mismatch
> >
> > The Accounting_Code in my table has a Text datatype.
> >
> > VB Procedure:
> >
> > Public Function Extract(Account_Code As String) As String
> > Dim Tokens() As String
> > Tokens = Split(Account_Code, ".", -1)
> > Extract = Mid(Tokens, 4, 4)
> > End Function
> >
> > Update Query:
> >
> > UPDATE SUB_1 SET SUB_1.Clearing_Account = Extract([Clearing_Account]);
> >
> > Visual Basic Editor is highlighting the "Extract = Mid(Tokens, 4, 4)"
> > line of code from my procedure, but as far as I know everything is
> > setup as text so there should not be a problem. ???
> >
> > Thanks for your time,
> > David
>
> Your code doesn't quite make sense. Tokens is an array of strings,
> which you are creating by splitting Account_Code on the "." character.
> Then you're trying to use the Mid function on the array itself -- but
> Mid() requires a string argument, not an array argument. Which part of
> Account_Code do you want? If you want the fourth element, you would
> just right
>
> Extract = Tokens(3)
>
> because the array is zero-based. Suppose you had an Account_Code of
> "A.B.C.D.E". Then
>
> Tokens(0) yields "A"
> Tokens(1) yields "B"
> Tokens(2) yields "C"
> Tokens(3) yields "D"
> Tokens(4) yields "E"
>
> If that explanation doesn't help, please tell us what you actually want
> Extract to return.
>
> --
> Dirk Goldgar, MS Access MVP
> www.datagnostics.com
>
> (please reply to the newsgroup)
>
>
>
.



Relevant Pages

  • Newbie: Array of pointers to strings questions.
    ... What I'm trying to do is extract information from one file and insert ... and the information in each case is extracted as a string. ... the relevant file is read into a temp file, ... but handling the array was a problem. ...
    (comp.lang.c)
  • Re: Function returns Datatype Mismatch
    ... > Public Function Extract(Account_Code As String) As String ... Tokens is an array of strings, ... Extract = Tokens ... Tokensyields "A" ...
    (microsoft.public.access.modulesdaovba)
  • Re: Help with String/Array manipulation
    ... I have an array with column widths. ... Next I have a string. ... would like to extract the number of characters based on the column- ...
    (perl.beginners)
  • Re: text search for a non-constant value?
    ... I am not able to find that behaviour of the row function in the online help. ... And indirectreturns the reference specified by a text string. ... And Row) yields 11. ... because it is an array formula. ...
    (microsoft.public.excel)
  • Re: Array problem (MySQL/PHP)
    ... You pass a string to 'TableData'. ... the same value (as returned from the same array '$row_Recordset1', ... same key '$slot') is appended to the end of that returned string. ... In the 'if' block you seem to be looking to extract a string from ...
    (alt.php)