Syntax Error: Comma in Query Expression of SQL Statement Access? - ms-access

I've been trying to make this statement work for some time but have ultimately lost the will to live.
In essence, I am attempting to filter a report to only certain Locations (So if you want the query to only include locations "Avonmouth" and "Bedford", that's what it would include, filtering the rest out) I have done this by implementing a check box system, so you can easily add locations to the filter. Unfortunately I keep getting syntax problems with the SQL script. Its a bit of a butchery, so please forgive me, but I have included the SQL below. (CHKBE = The check box)
WHERE QryTraining IN ((IIf [Forms]![ReportDeployer]![CHKAV]<>"" ,"Avonmouth",x),(IIf [Forms]![ReportDeployer]![CHKBA]<>"" ,"Basingstoke",x),(IIf [Forms]![ReportDeployer]![CHKBT]<>"" ,"Bedford Transport",x),(IIf [Forms]![ReportDeployer]![CHKBW]<>"" ,"Bedford Warehouse",x),(IIf [Forms]![ReportDeployer]![CHKBE]<>"" ,"Belfast",x),(IIf [Forms]![ReportDeployer]![CHKCA]<>"" ,"Carluke",x),(IIf [Forms]![ReportDeployer]![CHKEX]<>"" ,"Exeter",x),(IIf [Forms]![ReportDeployer]![CHKKI]<>"" ,"Kidderminister",x),(IIf [Forms]![ReportDeployer]![CHKKN]<>"" ,
"Knowsley",x),(IIf [Forms]![ReportDeployer]![CHKTE]<>"" ,"Teva",x),(IIf [Forms]![ReportDeployer]![CHKWI]<>"" ,"Wickford",x),(IIf [Forms]![ReportDeployer]![CHKYO]<>"" ,"York",x))
Each time I attempt to run it, it throws it back with a Syntax error.
Thanks in advance, T.

Not sure this will work any better but parens are in wrong place at beginning of each IIf() and maybe need apostrophe delimiters:
WHERE QryTraining IN (IIf([Forms]![ReportDeployer]![CHKAV]<>"" ,"'Avonmouth'",x), IIf([Forms]![ReportDeployer]![CHKBA]<>"","'Basingstoke'",x), IIf([Forms]![ReportDeployer]![CHKBT]<>"","'Bedford Transport'",x), IIf([Forms]![ReportDeployer]![CHKBW]<>"","'Bedford Warehouse'",x), IIf([Forms]![ReportDeployer]![CHKBE]<>"","'Belfast'",x), IIf([Forms]![ReportDeployer]![CHKCA]<>"","'Carluke'",x), IIf([Forms]![ReportDeployer]![CHKEX]<>"","'Exeter'",x), IIf([Forms]![ReportDeployer]![CHKKI]<>"","'Kidderminister'",x), IIf([Forms]![ReportDeployer]![CHKKN]<>"","'Knowsley'",x), IIf([Forms]![ReportDeployer]![CHKTE]<>"","'Teva'",x), IIf([Forms]![ReportDeployer]![CHKWI]<>"","'Wickford'",x), IIf([Forms]![ReportDeployer]![CHKYO]<>"","'York'",x))
Probably need to use empty string or some text like "N/A" in place of the x.
A BOUND checkbox must be either True or False (Yes/No), never an empty string. An UNBOUND checkbox can be set for triple state, in which case it could return True/False/Null, again never an empty string. So I am not sure why comparison to empty string. Just test for True.
IIf([Forms]![ReportDeployer]![CHKAV], "'Avonmouth'", "")

Related

Found some VBA code in a project and I'm wondering what this line does

I have a question about a line of code in a vba project I am working on. What does this statement actually mean? I know there is no context here and I could post more code but I'm not sure if someone could just look at this and let me know what this is doing.
txtTerminationDate.Locked = (isLocked Or cboTypeSelect.Column(1) = "Regular")
.locked is a boolean that sets whether you can edit the text box. So it is trying to set it to either true or false based on the logic that follows.
In English, set locked to true if the boolean isLocked is true, or if the value of cboTypeSelect.Column(1) equals "Regular".
if you are asking about TextBox.Locked research can be found here (as answered above) TextBox.Locked
if you are asking about the equal signs, it is useful to know that the first one is an assignment operator and the second is a comparison operator (like an inline if comparison). The equal sign is said to be 'overloaded' in vb.

Loop over tfilefetch while passing different paging token in Talend

Well, this scenario may be quite familiar but I couldn't find the solution.
Scenario:
I am making a REST API call through tFileFetch and I get a json out of it. I parse it to get paging token and more result through tflowtoiterate. Now if more result is equals true, I have to call the same tFileFetch component to get the new set of json using new pagination result.
I have to loop through tFileFetch until the 'more result' is false.
My approach:
Access token-pagination-tFileFetch_1->JSON->tflowtoIterate->more result=true->IF [moreresult=true]->tFileFetch_2->JSON->tFlowtoIterate->more result=true->tLOOP [moreresult.equals{true)->tFileFetch_2->
After tFileFetch2 I have used tSetGlobalVar to put pagination as common var to pass to tFileFetch2
I am not sure whether this approach is appreciable or not, please suggest any improvements if any?
I have actually covered it by myself. 'code' Add SubJob Ok from tLoop to tFileFetch and add condition in tLoop which say until your condition matches 'more result' is false. Finally added delimited output with append mode

ms-access localization and default boolean values

Our access client generates on the fly SQL inserts, update and delete instructions to be sent on a MS-SQL Server. Most users have the runtime version of Access 2007, and a few use the complete MS-Access version, 2003 or 2007. This morning one of our new users abroad, using a french/complete version of Access 2003, was unable to update data containing boolean fields.
It appeared that these fields are, in the french version of Access, populated with "Vrai/Faux" instead of "True/False" values. The problem was solved by installing the 2007 access runtime.
But I'd like to find a permanent solution, where I'd be able to read from somewhere which localized version of Access is in use and 'translate' the localized True/False values to standard True/False. I already checked the regional settings of the computer without success, so it is somewhere else. Any idea?
EDIT: Following JohnFX proposal, it is effectively possible to convert from local True/False to universal True/False with this simple function:
Function xBoolean(xLocalBooleanValue) as Boolean
if cint(xLocalBooleanValue) = -1 Then
xBoolean = True
endif
if cint(xLocalBooleanValue) = 0 Then
xBoolean = False
endif
end function
EDIT: following #David's comments, I changed the favorite solution. His proposal is smarter than mine.
EDIT: I am getting the Vrai/Faux values by reading the value of a field in a recordset:
? debug.print screen.activeForm.recordset.fields(myBooleanField).value
Vrai
True is NOT FALSE, or NOT 0, in all cases, no matter the localization or the database format.
So, if you replace all tests for True with NOT 0 and all tests for False with =0, then you've avoided the issue of localization of the Access keywords (I'm surprised that VBA and the Jet and Access expression services would not still understand True/False, though), as well as whichever convention your database engine uses for storing Boolean values.
In general, your data access layer ought to be abstracting that away for you. Both ODBC and ADO do it automatically, so you work with the Boolean values you know and it's taken care of for you transparently, in my experience.
I'm also still puzzled about the question, as it sounds like a display/formatting issue, but use NOT 0 and =0 for True and False avoids the problem entirely in all cases.
EDIT: In regard to the function edited into Philippe's question:
Is there a reason you've implicitly defined your function's parameter as a variant? Is that what you mean? If it's passed a Null, it's going error out on the first CInt(), as CInt() can't accept a Null.
Also, there's a logic problem in that in VBA any number but 0 is supposed to return True. It's also completely redundant code. This is simpler and returns the correct result in all cases:
Function xBoolean(xLocalBooleanValue As Vriant) as Boolean
If CInt(xLocalBooleanValue) <> 0 Then
xBoolean = True
End If
End Function
Or, pithier still:
Function xBoolean(xLocalBooleanValue As Variant) as Boolean
xBoolean = (CInt(xLocalBooleanValue) <> 0)
End Function
And to handle Nulls passed in the parameter:
Function xBoolean(xLocalBooleanValue As Variant) as Boolean
xBoolean = (CInt(Nz(xLocalBooleanValue, 0)) <> 0)
End Function
I'm not sure that's necessary in the context you're currently using it, but I always hate writing code where I can imagine a case where it will error out -- even if I know it can't break in its present context, you never know where it might end up getting used, so should you anticipate a condition that can be handled, you should handle it.
Premature optimization?
No -- it's putting a safety lock on a weapon that keeps it from being misused.
(on the other hand, if it took more lines of code to handle the antipated error than the function started out with, I'd think twice about it)
Have you considered using -1/0 (Access is weird about booleans) instead of true/false in your update and delete queries?
Math is the universal language, yaknow.
Also, to avoid having to localize the UI so much, why not use check-boxes instead of a text field for booleans on your UI?
Simple:
Function xBoolean(bool As Variant) As Boolean
xBoolean = Abs(Nz(bool, 0))
End Function

Use a value from a combo/text box in a file path string

I have a form that I intend to allow users to browse powerpoint presentations through, because there are a lot of different briefs for metrics, which is what I use this database for. So, I already know how to set up everything, just got one little hang up.
If I place a combo box on the form to select from a list of different presentation, can I use that in the file path string (that I have to use to pull the ppt into theobject frame in access.
example:
"C:\Users\Justin\Desktop\" & cmbTitle & ".ppt"
I tried it and it gives me the error message variable not defined. I never defined a control before on in these things, would it be as a string?
I realize that the exact file path much match the entered value. Access 2000-2003/XP
Thanks as always guys!
You need to refer to the field as Me.cmbTitle. As it is written, it looks like you're calling the variable cmbTitle which doesn't exist.
Is the value of cmbTitle some ID/Integer field or is it the actual string value? You may want to use the immediate window to check this. Also, make sure the value of cmbTitle doesn't have any backslashes or spaces (That may require quotes?).
I'm somewhat confused as to what you're trying to do. I will write my answer assuming:
you have a form in an Access database.
on that form is combo box that lists the PowerPoint presentations your users are working with.
the bound column of the combo box lists the filename (without path) of each PPT file.
when the user selects a filename from the combo box, you want to display it in an unbound OLE object frame.
The code for that, assuming the list of PPT files is called cmbTitle, would be in the combo box's AfterUpdate event and would look like this:
Private Sub cmbTitle_AfterUpdate()
Dim strPresentation As String
If IsNull(Me!cmbTitle) Then Exit Sub
strPresentation = "C:\Users\Justin\Desktop\" & Me!cmbTitle & ".ppt"
Me!olePPT.SourceDoc = strPresentation
End Sub
Now, I can't get a test unbound OLE object frame to work with this, but it seems to me to be the right way to do it.
My suspicion is that you're either attempting to set the wrong property, or you've defined your OLE frame wrongly, but I can't offer any more advice on that without knowing more about what you're actually attempting to do, and exactly what line of code is causing the error.

Custom code in Reporting Services report

In Reporting Services I would like to add a parameter that contains data from a custom code block. Ideally, I would be able to run the following code (this is a simple testing example):
Function GetPeriods() As String()
Dim values As System.Collections.ArrayList =
New System.Collections.ArrayList()
For i as integer = 1 to 24
values.Add(i)
Next
Return values.ToArray()
End Function
and put the following in the "Text Field" of the parameter:
=Code.GetPeriods()
However, when I run the report, the parameter I apply this to is disabled and empty. Is there a different technique that should be used? Or am I doing something wrong?
If you're using SQL 2008 Reporting Services then you can have a look at this page which introduces the concept of using custom assemblies.
If you're using SQL 2005 Reporting Services then this link is the one you want.
It's a mostly trivial thing, simply compile your code into a class library and follow the instructions provided to allow your report to reference it.
You are returning an array item (an array of strings) into a text field. Instead, try returning a plain string. That should work. If you would still like to return an array list, you must basically bind it to a list control in your RDL. You can definitely do that with dataset extensions. However, I am not sure if there is any other easy way. Check the proprties of the list control and see if it allows you to directly bind to an array list.
You can create the same stored procedure on SQL Server and load parameter values from that procedure.
To access your members/functions implemented in custom code of SSRS report you should set the access modifier to "Public":
Public Function GetPeriods() As String
...
see article Writing Custom Code in SQL Server Reporting Services
I've been trying to do this same thing, set a simple list of parameter values from report code. None of the links in any of these answers shows how to do this and after quite a bit of digging around I don't think it's even possible. Yes it is possible to get the values from a database query, from a web service, or from a custom assembly, but each of these creates a lot of overhead compared to getting the list from a simple function call like =Code.GetValues(), where the function uses a For loop to create the values.
msvcyc is correct in pointing out that the parameter is expecting a string value, but the function is returning an array. I changed the return type to Array as suggested by prashant sable, but the select list is still grayed out, it does not work. And coldice is correct in saying that the access modifier should be Public.
In my digging around I found an article by James Kovac from 2005 that pointed out why this is not possible. The Parameters class has a get method, but no set method. In the VS 2008 object browser for SSRS 2008 the object name has changed, but it still does not contain a set method (see Microsoft.ReportingServices.Interfaces.IParameter.Name or .Value).
My current workaround is to just hard code the list of values, but if your value list needs to be dynamic then your only choices are database queries, web services, or custom assemblies. I think the easiest workaround of these three is to get the values from the database engine, as suggested by oleksiy.t, as long as you can write a query to return the value list you want. Your list of integers, or my list of time intervals, would both be easy queries to write. Otherwise you will need to use one of the other two workarounds.
I checked your code. The only thing that's wrong is your function returns String(). When I changed your method signature to return Array, it worked fine, in my report.
Change the signature to Function GetPeriods() As Array
Everything I've seen requires parameters and their respective settings to be part of the RDL.
That being said, if you're going to "hardcode" the values, you could create a dataset just for the report, perhaps in XML, or if it needs to be programmatically driven, do it in a web service.