469,286 Members | 2,399 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,286 developers. It's quick & easy.

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
Nov 12 '05 #1
2 34118
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" <ng****@hotmail.com> wrote in message
news:f7**************************@posting.google.c om...
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

Nov 12 '05 #2
left$() will return a string or generate an error if passed NULL
left() will return a string or NULL if passed NULL

"Nathan Given" <ng****@hotmail.com> wrote in message
news:f7**************************@posting.google.c om...
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

Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Marek Kotowski | last post: by
4 posts views Thread by Agnes | last post: by
3 posts views Thread by OutdoorGuy | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.