The SELECT statement includes a reserved word - vba

So when I try to run my code I get a Runtime Error '3141' "The SELECT statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect."
Here is my code
strSQL5 = " SELECT DatePart('m',[gs_MultiList_Daily/monthly]![Test_Date]) AS Char, MonthName(DatePart('m',[Test_Date])) AS [Month], DatePart('yyyy',[Test_Date]) AS [Year], Sum([gs_MultiList_Daily/monthly].LeaksLogged) AS LeaksLogged, Sum([gs_MultiList_Daily/monthly].[ME Samples]) AS [ME Samples], Sum([gs_MultiList_Daily/monthly].MSampleLogged) AS MSampleLogged, Sum([gs_MultiList_Daily/monthly].Saddle) AS Saddle, Sum([gs_MultiList_Daily/monthly].EntranceDia) AS EntranceDia, Sum([gs_MultiList_Daily/monthly].TappingTee) AS TappingTee, [gs_MultiList_Daily/monthly].LDIW, [gs_MultiList_Daily/monthly].[X-Ray], [gs_MultiList_Daily/monthly].[ETSP Inspection], [gs_MultiList_Daily/monthly].DFT, [gs_MultiList_Daily/monthly].CDT, Sum([gs_MultiList_Daily/monthly].[Mount Photos]) AS [Mount Photos], Sum([gs_MultiList_Daily/monthly].[Melt Index]) AS [Melt Index], Sum([gs_MultiList_Daily/monthly].PSampleLogged) AS PSampleLogged, Sum([gs_MultiList_Daily/monthly].Density) AS Density, " & _
" Sum([gs_MultiList_Daily/monthly].PE_WT) AS PE_WT, Sum([gs_MultiList_Daily/monthly].OOR) AS OOR, " & _
" Sum([gs_MultiList_Daily/monthly].Poly_OD) AS Poly_OD, Sum([gs_MultiList_Daily/monthly].[WaterBath Out]) AS [WaterBath Out], Sum([gs_MultiList_Daily/monthly].[WaterBath In]) AS [WaterBath In], Sum([gs_MultiList_Daily/monthly].FTIR) AS FTIR, Sum([gs_MultiList_Daily/monthly].OIT) AS OIT, Sum([gs_MultiList_Daily/monthly].[Steel WT]) AS [Steel WT], Sum([gs_MultiList_Daily/monthly].[Steel Hardness]) AS [Steel Hardness], Sum([gs_MultiList_Daily/monthly].[Steel OD]) AS [Steel OD], Sum([gs_MultiList_Daily/monthly].[TIMP Corrosion]) AS [TIMP Corrosion], Sum([gs_MultiList_Daily/monthly].[Chem Analysis]) AS [Chem Analysis], Sum([gs_MultiList_Daily/monthly].[Steel Mounts]) AS [Steel Mounts], Sum([gs_MultiList_Daily/monthly].[Mounts Polished]) AS [Mounts Polished], Sum([gs_MultiList_Daily/monthly].Etch) AS Etch FROM [gs_MultiList_Daily/monthly] " & _
" GROUP BY DatePart('m',[gs_MultiList_Daily/monthly]![Test_Date]), MonthName(DatePart('m',[Test_Date])), DatePart('yyyy',[Test_Date]) " & _
" ORDER BY DatePart('yyyy',[Test_Date]) "
This is exactly how it is displayed on the window. The SELECT statement is really long and did not fit in a single line so I broke it up into 3 using " & _ " I also have spaces at both ends of the " so im clueless to where the error is coming from. Can someone please direct me to the correct path ? thank you!

CHAR is a reserved word, don't use it as an alias (or add [] brackets, but really, don't use it).
Generally, when you encounter this error, run each field name through the list of reserved words.

Related

RDLC - IIF expression error - Argument not specified for parameter 'FalsePart'

I have a RDLC report with following expression.
=Iif(
(Fields!EnvironmentalAuditorCompany.Value = "" and Fields!EnvironmentalAuditorPerson.Value<>""),
(Fields!EnvironmentalAuditorPerson.Value),
(
Iif(Fields!EnvironmentalAuditorPerson.Value = "" and Fields!EnvironmentalAuditorCompany.Value<>""),
(Fields!EnvironmentalAuditorCompany.Value),
Iif(Fields!EnvironmentalAuditorPerson.Value="" and Fields!EnvironmentalAuditorCompany.Value=""), " - ",
(Fields!EnvironmentalAuditorPerson.Value) & "," & vbCr & vbLf & (Fields!EnvironmentalAuditorCompany.Value)
)
)
However, I am getting the below error message
The Value expression for the textrun ‘EEnvAuditorPerson.Paragraphs[0].TextRuns[0]’ contains an error: [BC30455] Argument not specified for parameter 'FalsePart' of 'Public Function IIf(Expression As Boolean, TruePart As Object, FalsePart As Object) As Object'.
Please assist on this to resolve.
Below are the cases for the expression:
1. Might be a chance either one of the fields having value (AuditPerson/AuditCompany), if so fill the corresponding fields
2. Both of the fields will be empty, if so put - (Hypen)
3. Both of the fields having value, if so handle the value with comma separated in new line
You have mess of brackets in your expression and FalsePart was indeed missing for some of the IIFs. I'm not going to attempt to understand the meaning of your expression, but simply copying it into text editor and lining up your IIFs and fixing corresponding brackets, I got this:
=Iif(
(Fields!EnvironmentalAuditorCompany.Value = "" and Fields!EnvironmentalAuditorPerson.Value<>""),
(Fields!EnvironmentalAuditorPerson.Value),
Iif(
(Fields!EnvironmentalAuditorPerson.Value = "" and Fields!EnvironmentalAuditorCompany.Value<>""),
(Fields!EnvironmentalAuditorCompany.Value),
Iif(
(Fields!EnvironmentalAuditorPerson.Value="" and Fields!EnvironmentalAuditorCompany.Value=""),
" - ",
(Fields!EnvironmentalAuditorPerson.Value) & "," & vbCr & vbLf & (Fields!EnvironmentalAuditorCompany.Value)
)
)
)

IF NOT ISBLANK - syntax issue

=IF(NOT(ISBLANK(VLOOKUP(Table1[Company Name],Billing_Info[#All],5,FALSE) & ", " &VLOOKUP(Table1[Company Name],Billing_Info[#All],6,FALSE) & " " &VLOOKUP(Table1[Company Name],Billing_Info[#All],7,FALSE),""))
What am I doing wrong - get wrong number of arguments? Trying to eliminate the comma if there is no data.

Vb.Net Search between two dates ms access

I'm using vb.net Windows Form Application, and I have two datepicker and I want to filter between two dates...
I've tried this code :
Me.DBBindingSource.Filter = "[Data ardhjes] BETWEEN " & dtpDataArdhjes.Value.Date & " AND " & dtpDataArdhjesNE.Value.Date
And I got this error:
Additional information: The expression contains unsupported operator
'Between'.
and some other codes but it does not work..
[Data ardhjes] is on table, and dtpDataArdhjes is datetimepicker from the table
and dtpDataARdhjesNe is just a dateTimepicker, sa I want to search between two dates in same column named [Data Ardhjes]
any suggestion please ?
Try this :
Me.DBBindingSource.Filter = "[Data ardhjes] BETWEEN " & dtpDataArdhjes.Value.ToString("#yyyy/MM/dd#") & "
AND " & dtpDataArdhjesNE.Value.ToString("#yyyy/MM/dd#")
I got the answer:
Me.DBBindingSource.Filter = String.Format("[Data ardhjes] >= #{0:M/dd/yyyy}# AND [Data ardhjes] <= #{1:M/dd/yyyy}#", _
dtpDataArdhjes.Value, _
dtpDataArdhjesNE.Value)
It works great now..

What does "& _" mean in VB?

I'm copying some query statements from a legacy VB app to a C# app. I am not familiar with VB, although looking at it makes me want a VB (Victoria Bitter). I have come across queries constructed like this:
*SELECT dp_duckbill_accounts.platypus_no AS duckbill, t_accounts.name AS Name " & _
"FROM t_accounts INNER JOIN dp_duckbill_accounts ON t_accounts.account_no = dp_duckbill_accounts.account_no " & _
"ORDER BY dp_duckbill_accounts.platypus_no*
The "& _" give me pause. If it was just "&" I would think it corresponds to "+" in C# to concatenate strings. But what in the world is the point of the underscore? Note the ampersand and the underscore are separated by a space.
The underscore is the line continuation character. It allows the concatenation to include a different line. Like so:
x = "Hello " & "World"
x = "Hello " & _
"World"
'this won't compile (pre vb.net 2010, anyway)
x = "Hello " &
"World"
Line Continuation on MSDN
How to: Break and Combine Statements in Code (Visual Basic)
_ means continue the statement on the following line.
so ... & _ means continue concatenating the string on the following line.
text = "One line string"
text = "Two line " & _
"string"
That is just a line continuation character that lets you continue to the next line.
& - is used for string concatenation in same line.
example - sConcatenatedString = "First" & "Second"
& _ - is used For string concatenation in different lines.
example - sConcatenatedString = "First" &_
"Second"

How to put another line of string (still in one phrase) in vb.net?

I want to put or cut my string into couple of lines. How could I do that?
this is the line of codes I want to cut (but they are still in string).
sql = "INSERT INTO tblClientInfo (genClientID, fullName, address, comaker, colateral, atmPIN, principal, "
& "interest, principalInWords, terms, interestPerMonth, principalperMonth, totalPayment, interestPercentage, "
& " interestBal, principalBal, theDate, totalBal)"
This code returns an error. What is the proper way of concatenation or cutting a long string?
You need to indicate that the line continues to the next line by suffixing each line to be continued with a space followed by an underscore, as follows:
sql = "INSERT INTO tblClientInfo (genClientID, fullName, address, comaker, colateral, atmPIN, principal, " _
& "interest, principalInWords, terms, interestPerMonth, principalperMonth, totalPayment, interestPercentage, " _
& " interestBal, principalBal, theDate, totalBal)"
Additional reference: http://msdn.microsoft.com/en-us/library/aa711641%28v=vs.71%29.aspx
I like String.Concat() because you don't need line-continuation underscores and you don't need ampersands. Just looks cleaner.
sql = String.Concat(
"INSERT INTO tblClientInfo (genClientID, fullName, address, comaker, colateral, atmPIN, principal, ",
"interest, principalInWords, terms, interestPerMonth, principalperMonth, totalPayment, interestPercentage, ",
"interestBal, principalBal, theDate, totalBal)" )