Connecting Tech Pros Worldwide Help | Site Map

Difference between Left() and Left$() function

 
LinkBack Thread Tools Search this Thread
  #1  
Old November 12th, 2005, 09:56 PM
Nathan Given
Guest
 
Posts: n/a
Default Difference between Left() and Left$() function

Hello All,

I am trying to debug a broken query. The query uses
Left$([blahblah],4) instead of Left([blahblah],4).

What is the difference between the Left() and Left$() functions in
Microsoft Access?

Thanks!
--
Nathan

Keywords: MS Microsoft Access Functions Function Left Left$ Left()
Left$() Query

  #2  
Old November 12th, 2005, 09:56 PM
Allen Browne
Guest
 
Posts: n/a
Default Re: Difference between Left() and Left$() function

The trailing $ is a type declaration character for the String data type in
VBA.

The result returned from Left$() is a string, whereas Left() returns a
Variant.

You must use Left(), not Left$() if there is any chance of Null values,
since the Variant can be Null but the String cannot. To demonstrate that:
1. Press Ctrl+G to open the Immedate window.

2. Enter:
? Left(Null,1)
The answer is Null.

3. Now enter:
? Left$(Null,1)
This generates Error 94. Since the result should be Null, and the String
cannot be Null, you receive the error, "Invalid use of Null".

If you are dealing with string values, in VBA code, Left$() will be slightly
more efficient, as it avoids the overhead/inefficieny associated with the
Variant. However, if there is *any* chance that Nulls may be involved, use
Left(), or else explicitly handle the Null with something such as Nz().

More information on Nulls:
http://allenbrowne.com/casu-11.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Nathan Given" <ngiven@hotmail.com> wrote in message
news:f749d926.0405040739.6ec5eedb@posting.google.c om...[color=blue]
> Hello All,
>
> I am trying to debug a broken query. The query uses
> Left$([blahblah],4) instead of Left([blahblah],4).
>
> What is the difference between the Left() and Left$() functions in
> Microsoft Access?
>
> Thanks!
> --
> Nathan
>
> Keywords: MS Microsoft Access Functions Function Left Left$ Left()
> Left$() Query[/color]


  #3  
Old November 12th, 2005, 09:56 PM
paii, Ron
Guest
 
Posts: n/a
Default Re: Difference between Left() and Left$() function

left$() will return a string or generate an error if passed NULL
left() will return a string or NULL if passed NULL

"Nathan Given" <ngiven@hotmail.com> wrote in message
news:f749d926.0405040739.6ec5eedb@posting.google.c om...[color=blue]
> Hello All,
>
> I am trying to debug a broken query. The query uses
> Left$([blahblah],4) instead of Left([blahblah],4).
>
> What is the difference between the Left() and Left$() functions in
> Microsoft Access?
>
> Thanks!
> --
> Nathan
>
> Keywords: MS Microsoft Access Functions Function Left Left$ Left()
> Left$() Query[/color]


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.