Updating Fields in a Table with Values from Query - sql

I'm struggling to understand why my event code for updating a Microsoft Access form field is only half working.
I have a query, we'll call DataQuery, that selects 3 column values from what we'll call Table1 that looks like the following:
**Part** **Description** **Revision**
10-123 Descrip1 A
10-342 Descrip2 D
10-232 Descrip3 E
I have another table where I'd like to assign the values from description and revision to fields in another table, we'll call Table2, based on picking a value in a combo box.
For instance:
We select a value of 10-342 in our combo box, then the values "Descrip2" and "D" get assigned to fields in Table2.
I can get this to work for whatever column I have in position one, but not position two.
My small vba code:
Private Sub ComboBox_AfterUpdate()
Me.DescriptionField_Table2 = Me.ComboBox.Column(1)
Me.RevisionField_Table2 = Me.ComboBox.Column(2)
Me.Requery
End Sub
Where "ComboBox" row source is DataQuery mentioned previously.
As stated, "Me.DescriptionField_Table2 = Me.ComboBox.Column(1)" works as intended, but the second line seems to be getting ignored. I feel like I'm missing something super simple here, but I'm can't figure it out.

I knew this was something simple...
Gustav, in the comments, answered my issue:
Set property ColumnCount of the combobox to 3.

Related

PowerQuery - Using a cell in a table as part of the code in a query (dynamically or not)

I am trying to use a cell as a parameter in Excel powerquery. The query works without this, but I have to manually input the values, which I need to constantly change them in the query in other to get the results that I want.
Query (Advanced Editor):
let
Criteria01 = Excel.CurrentWorkbook(){[Name="Servers"]}[Content][ServerSearch]{0},
Criteria02 = Excel.CurrentWorkbook(){[Name="Servers"]}[Content][ServerSearch]{1},
Criteria03 = Excel.CurrentWorkbook(){[Name="Servers"]}[Content][ServerSearch]{2},
Source = Sql.Database("SERVERNAMEHERE", "DATABASENAMEHERE", [Query="SELECT DISTINCT [...........] AND (TABLEPREF.COLUMNHERE like '%MANUALVALUE01%' OR#(lf)TABLEPREF.COLUMNHERE like '%MANUALVALUE02%' OR#(lf)TABLEPREF.COLUMNHERE like '%MANUALVALUE03%' OR#(lf)TABLEPREF.COLUMNHERE like Criteria01)#(lf)#(lf)#(lf)order by 1 asc"])
in
Source
"Servers" is the table name and "ServerSearch" is the column header. If I check the step for Criteria01/etc it will show me the correct value of that table that I need to use.
Original query done in Sql-Server. I have no problems when running the query with only LIKE '%MANUALVALUES%' lines.
My main goal is to automatically get N values of "MANUALVALUES" from a table in a sheet, which will be used as an input for comparing WHERE TABLEPREF.COLUMNHERE like '%VALUEHERE%'. I must use this and I can't get the whole table/database because there are way too many results besides the ones that I want.
However for test purposes at this moment, I am trying to use only 1-3 values, the first 3 of this table (Criteria{0}{1}{2} in the query above). However, if I try to do something like TABLEPREF.COLUMNHERE like Criteria01 I get the following error:
DataSource.Error: Microsoft SQL: Invalid column name 'Criteria01'.
Details:
DataSourceKind=SQL
DataSourcePath=dalsql390;itdw
Message=Invalid column name 'Criteria01'.
Number=207
Class=16
So my questions are:
I am getting the table cell value by the right way? Meaning:
Excel.CurrentWorkbook(){[Name="Servers"]}[Content][ServerSearch]{0}.
How do I refer this value in my query? Since the way that I wrote
that query bought me that error.
Also please note that if change TABLEPREF.COLUMNHERE like
Criteria01 to CHG1.CI_Name like "Criteria01" I get the
following error:
Expression.SyntaxError: Token Comma expected.
After fixed 1 and 2, how can I use this dynamically? For
example, instead of getting values of index 1 2 3, what if I want to
use a whole table? I know that using
Excel.CurrentWorkbook(){[Name="Servers"]}[Content] will bring me the whole table of values (1 column, unknown number of rows), but
how do I use this table content 1 by 1 in my query?
That will get the value, but you can't refer to steps inside of text values by putting the step name inside of it.
You have a couple options for doing this dynamically.
Use Value.NativeQuery to create a parameterized query where you can pass in other values as parameters. For example, Value.NativeQuery(Sql.Database("SERVERNAMEHERE", "DATABASENAMEHERE"), "select #a, #b", [a = 1, b = "x"]) will return the table [1, x]. You can put in the step name in the record value to pass that it (e.g. replace "x" with Criteria01).
Add the text values directly in the query field, e.g. [Query = "select " & Criteria01 ";"]. This is highly discouraged since this can lead to SQL injection issues.
For the third question, it depends what you want to do with the list of values. At some point you will likely need List.Accumulate to turn them all into a single text value which can be placed in the query value, and maybe to turn them into a record to place into the parameters value.

Access 2013 - Textbox formula producing a #Name? error

I have a textbox that I want to display one of 2 values -
1. A Date
2. the word "Incomplete"
I've tested this in the immediate window and it works perfectly.
Here's my logic:
If my desired condition were true, all records would have a date, if the dates are different or if some records have no date, then it would be "Incomplete"
This can be achieved analyzing this query called SP_ALL_ACTUALS_AS_OF:
SELECT tbl_SP.Actuals_AsOf
FROM tbl_SP
GROUP BY tbl_SP.Actuals_AsOf;
If the query is my desired condition then only one record comes up - "The date" that is in every single record in the Actuals_AsOf field of tbl_SP
However, if there are blanks here and there, there will be a minimum of 2 records, one of which will not be a date. So if I find 1 grouping that is not a date, then the entire condition should be "Incomplete"
so here is the formula in the textbox
IIf(DCount("[Actuals_AsOf]","SP_ALL_ACTUALS_AS_OF",IsDate([Actuals_AsOf])=False)=1,"Incomplete",Nz(DLookUp("[Actuals_AsOf]","SP_ALL_ACTUALS_AS_OF"),"Not pulled"))
I tested it in the immediate window and all is fine. However, when I implement this textbox on a form, I get a #Name? error. Why?
Try with:
=IIf(DCount("*","SP_ALL_ACTUALS_AS_OF","IsDate([Actuals_AsOf])=False")=1,"Incomplete",Nz(DLookUp("[Actuals_AsOf]","SP_ALL_ACTUALS_AS_OF"),"Not pulled"))
If you put your 'formula' in the Control Source of the Textbox you have to:
1) begin your Control Source string with an equal ('=')
2) Replace all commas (',') with semi-colon (';')
You can also set your Textbox with VBA in the onCurrent eventProc or onLoad event of your form, and your formula as to be written as in your post.

Replace null with zero in crosstab query in Telerik

I just created 2 cross table using wizard function of Telerik Standalone report designer tool
since ISCED 5 has values for private and public its showing properly
using same query I created second cross tab and
but since ISCED 6 table doesnt have values for "public" section its showing like this
how to show as zero for public section 2nd cross tab (when no values for specific row)
You should modify the value of the field using an expression to evaluate your condition.
Select the textbox containing the data corresponding to the column you like to format when the value is null.
In the property pan on the right select "Value"
Write in there your expression, it should be something like this:
=Iif(Fields.MyField IS Null,"0",Fields.MyField)
You should also consider if the value instead of null is empty and eventually cover this case in the expression if applicable.
= Iif(Fields.MyField IS Null OR Fields.MyField = "", "0", Fields.MyField)
More information on conditional formatting can be found here.
Let us know if this works for you.

access query no result

Can some one tell me what is wrong with this query as I run this query and refer combo box value on the form but it is not returning any value?
SELECT [2G_KPI].CSSR
FROM 2G_KPI
WHERE ((([2G_KPI].CSSR) Like [Forms]![Form1]![segment_name].[Text]));
In ComboBox you there are 3 things, selectedValue , SelectedIndex and Selected text
Based on how you have coded,debug and check what value goes in the "predicate of your where clause".

How to create list as a parameter in SSRS?

I have a report in 2005 SSRS which I want to add a parameter to. The parameter would be comprised of a group of zip codes, but be selected as a single item in the list.
For example, I would like to have 5 zip codes as one selection in the list and 3 for another, etc:
Select 11111,22222,33333,44444,55555,66666 AS Boondock
Select 77777,88888,99999 AS Timbuck
Select Zip Codes NOT IN (11111-99999) AS Everything Else
So my selections in the dropdown would be:
Boondock
Timbuck
Everything Else
Can anyone help me with how I should go about creating this parameter?
Create a simple string parameter to present to the user. Let's call it ZipCodeSet.
Create a dataset that examines the #ZipCodeSet parameter and returns the appropriate list of zip codes. Call it ZipCodeSelection.
Create an internal multivaue parameter that uses ZipCodeSelection as both its Available Values and Default Values. Call it SelectedZipCodes.
Use SelectedZipCodes in your report's datasets.
The easiest solution here would probably to use a Calculated Field on your dataset, called LocationDescription, for example:
=SWITCH(Fields!ZipCode >= 11111 and Fields!ZipCode <= 66666, "Boondock", Fields!ZipCode >= 77777 and Fields!ZipCode <= 99999, "Timbuck",True, "Everywhere Else")
The lone true statement at the end is due to the SWITCH expression reading left-to-right and exiting once it evaluates one of the switches as TRUE. This way for each of the items in your table of ZipCodes you will always end up with a TRUE result.
I assume you're evaluating a range of ZipCodes, and not exact values of 11111,22222, and so on? If so, the switch will have more values. A sample of your data would help if you want an exact answer.
Once you have built your Calculated Field, you can then set up a Parameter (called #LocationParameter) with available values based on a query of your LocationDescription field, then just filter your dataset using:
Expression:
= Fields!LocationDescription
Operator: =
Value:
#LocationParameter
(if you want multiple selections on your parameter, change the operator to IN)
Hope that helps.