|
-
Aug 26th, 2009, 03:53 AM
#1
Thread Starter
Frenzied Member
Some explanation
Can anybody explain the uses of ampersand sign over here.Kindly let me know the idea.
Code:
StrSql = "Select * from " & tablename
-
Aug 26th, 2009, 04:28 AM
#2
Re: Some explanation
I concatenates what ever value is in tablename, if any, to the select statement. For example:
tablename = "Contacts"
Then StrSql will contain:
"Select * from Contacts"
-
Aug 26th, 2009, 04:56 AM
#3
Re: Some explanation
 Originally Posted by firoz.raj
Can anybody explain the uses of ampersand sign over here.Kindly let me know the idea.
Code:
StrSql = "Select * from " & tablename
& (ampersand) concatenates two strings. In other languages this is usually done with a + (plus) operator (which you can use here also).
So,
StrSql = "Select * from " & tablename
concatenates "Select * from " and tablename. Since tablename is a variable, the value of tablename is used.
-
Aug 26th, 2009, 05:19 AM
#4
Re: Some explanation
I'd stay away from the plus sign for concatenations as a practice. Although it will work in the example given it can cause a type mis-match error with numerics. That's just my way and that doesn't make it right. This will cause an error (lngValue can probably be wrapped to make it work but why deal with that):
Code:
Dim strsql As String
Dim lngValue As Long
lngValue = 10
strsql = "Select * from TableName where Value = " + lngValue
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|