I have a textbox named "Search" and code that filters a customer out by name. I also want to display the whole table if the textbox is empty but don't know how to do it.
NOTE : I am using Microsoft Access.
Here is my code :
SELECT * FROM Customers
WHERE Forms.[Form1].[Text4] = Forms.[Form1].[Text4] AND FirstName=Forms.[Form1].[Text4];
Thank you for any help.
You need validate if text is empty or filter to another rules, this can be something like this:
SELECT * FROM Customers WHERE Forms.[Form1].[Text4] IS NULL OR FirstName = Forms.[Form1].[Text4];
Related
I encounter some problems that i don't understand with APEX.... Well, let's be specific.
I ve got a select element retrieving a top 50 of most liked url (P11_URL). This is populate by a table view, TOp_Domains.
I create an element called "Context" that have to print all text containing the URL selected by the user from the element select. Those Texts come from another table, let's say "twitter_post".
I create a dynamic action (show only) with this sql/statement:
Select TXT, NB_RT, RANK
from myschema.twitter_post
where TXT like '%:P11_URL%'
group by TXT, NB_RT, RANK
.... and it doesn't work... I think APEX don't like like clause... But i don't know how to do. Let's keep in min an url could have been shared by multiple Tweets, that's why this element "context" is important for me.
I tried to bypass the problem by building a State (in french Statique) and a dynamic action that will refresh the state but it doesn't work neither... bouhououououou
TriX
Right click on the 'P11_URL' and create DA. Event :change, Item:P11_URL. As the true action of the DA, select 'Set Value'. Write your query in the sql stmt area. In the page items to submit, select 'P11_URL' . In the 'Affected Items': select 'Context'.
Query should be :
Select TXT, NB_RT, RANK
from myschema.twitter_post
where TXT like '%' || :P11_URL || '%'
group by TXT, NB_RT, RANK
So
Thanks to #Madona... Their example made me realised my mistake. I wrote the answer here for futher help if somebody encouter the same porblem.
A list select element get as arguments a display value (the one you want to be shown in your screen.... if you want so....^^ ) and a return value (in order, I think to linked dynamic actions). So to solved my problem i had to shape my sql statement as:
select hashtags d, hastags r
from my table
order by 1
[let s say that now in Apex it s an object called P1_HASHTAGS]
First step problem solving.
In fact, the ranking as second value, as i put into my sql statement was making some mitsakens into my 'Where like' clause search... well... Newbie am i!
Second step was to correctly formate the sql statement receiving the datas from my select lov (P1_HASHTAGS) into my interactive report. As shown here:
Select Id, hashtags
from my table
where txt like '%'||:P1_HASHTAGS||'%'
And it works!
Thank you Madona your example helped me figure my mistakes!
Is possible do Select * form DynamicValue to perform a query like this in Navision?
Thanks in advance
To perform a sql query li this select * from DynamicValue You must do something like this.
Imagine that you have a table and you are going to show the data in a page or form.
Variables:
RecDynamicValue (Table).
PagDynamicValues (Page).
Code:
RecDynamicValue.RESET; //Clean filters
CLEAR(PagDynamicValues);
PagDynamicValues.SETTABLEVIEW(RecDynamicValue); //Set RecDynamicValue (Table)
PagDynamicValues.RUN; (Open Page)
In this code when page is open you can see al records from DynamicValue table like a Select * from DynamicValue.
If you need perform a loop for all records from DynamicValue table in code try this:
RecDynamicValue.RESET;
IF RecDynamicValue.FINDSET THEN REPEAT //Repeat clausule for a loop
//Loop...
//Loop...
//Loop...
UNTIL RecDynamicValue.NEXT = 0; //Repeat until last value
In all cases first you need declare a variable, SubType = Record and specified ID or name of record.
You can not change the value of the table variable by code.
But perhaps you can use RecordRef function to do that.
For example:
RecRef.OPEN(27); //Id of ItemTable
RecRef.FINDFIRST;
FldRef := RecRef.FIELD(3); // Item.Description;
FldRef.VALUE('New description');
RecRef.MODIFY;
In your case your DynamicValue is parameter to RecRef.OPEN("Your Dynamic Value") here you need specified value ID of your table.
You can also perform a loop using RecorRef.
I've just started using microsoft access so I don't really know how to solve this. I would like to use an update query to add a value from a form to a value on a table.
I originally used the SUM expression which gave me an error saying it was an aggregate function.
I also tried to add the two values together (e.g [field1] + [field2]) which as a result gave me a value with both numbers together instead of adding them together.
The following is the SQL I'm using:
UPDATE Votes
SET Votes.NumVotes = [Votes]![NumVotes]+[Forms]![frmVote]![txtnumvotes]
WHERE (((Votes.ActID) = [Forms]![frmVote]![combacts])
AND ((Votes.RoundNum) = [Forms]![frmVote]![combrndnum]))
I want to add a value [txtnumvotes] a form to a field [NumVotes] from the table [Votes].
Could someone please help me?
You can specify the expected data type with parameters:
PARAMETERS
[Forms]![frmVote]![txtnumvotes] Short,
[Forms]![frmVote]![combacts] Long,
[Forms]![frmVote]![combrndnum] Long;
UPDATE
Votes
SET
Votes.NumVotes = [Votes]![NumVotes]+[Forms]![frmVote]![txtnumvotes]
WHERE
(((Votes.ActID) = [Forms]![frmVote]![combacts])
AND
((Votes.RoundNum) = [Forms]![frmVote]![combrndnum]))
Without the specification, Access has to guess, and that sometimes fails.
I did this below. What I'd like is to create a table where the prompt (TEXT) gets for values a where statement. Values are WHERE PERFORMING_FLAG = "Yes" , it display "Yes" to the user, and WHERE PERFORMING_FLAG = "No" that displays "No" to the user, and /* */ which displays "All"
So I wrote the code below, and it doesn't work.
What I want is being able To make the user choose between two options that are WHERE statement and one option that is nothing (so no WHERE statement).
How should I do my prompt or correct the code ? The prompt is &PERFORMING_FLAG
Or I guess there is a possibility to make it more clear, could be you please enlighten me ?
PROC SQL;
CREATE TABLE TRAVAIL.Q113_INPUTS AS
SELECT t1.ID_INTERNATIONAL,
t1.NOM_TIERS,
t1.CD_COTATION,
t1.'Lb Secteur EIS GB'n,
t1.'Zone Resp'n,
t1.ID_FAC,
t1.LB_ENGAGEMENT_GB,
t1.'Type Encours'n,
t1.'Type Encours GB'n,
t1.IND_BILAN_HORS_BILAN,
t1.DT_AUTO,
t1.DT_ECH,
t1.'Devise Final1'n,
t1.'Devise Final'n,
t1.SumOfMT_UTIL_EUR,
t1.SumOfMT_AUTO_EUR,
t1.PNU_conf,
t1.'Regulatory_RWA'n,
t1.SumOfMT_EXPO_IRBA,
t1.TX_CCF_IRBA,
t1.SumOfX_EDF1_IRBA,
t1.SumOfX_GRR_IRBA,
t1.SumOfX_MAT_IRBA,
t1.PERFORMING_FLAG,
t1.IND_CONF,
t1.'Business Country'n,
t1.'LB Pays Resp'n,
t1.'Lib Metier 25'n,
t1.'Lib act agg 25'n,
t1.LB_GRP_AFFAIRE,
t1.RATING_GROUPE,
t1.C3_CLIENT_LINE,
t1.CD_GRP_AFFAIRE,
t1.Credit_Type_Profiling,
t1.CD_TP_CTRP_CAPRI,
t1.LIB_METIER_BFI,
t1.FORTIS_FLAG,
t1.CD_ENGAGEMENT,
t1.LB_ENGAGEMENT
FROM TRAVAIL.Q113_INPUTS_1 t1
&PERFORMING_FLAG.;
QUIT;
Maybe you are looking for the %WINDOW statement? Or the window statement from Data step?
SQL query in Ms-Access
INSERT INTO tblTmpEventLog( TrackingNumber, PartNumber, PartNumberChgLvl,
EnteredBy, EventTypeSelected, EventDate )
SELECT DISTINCT tblRevRelLog_Detail.RevRelTrackingNumber,
tblRevRelLog_Detail.PartNumber, tblRevRelLog_Detail.ChangeLevel,
[Forms]![frmEventLog_Input]![EnteredBy] AS EnteredBy,
[Forms]![frmEventLog_Input]![EventTypeSelected] AS EventTypeSelected,
CDate([Forms]![frmEventLog_Input]![EventDate]) AS EventDate
FROM tblRevRelLog_Detail LEFT JOIN tblEventLog
ON (tblEventLog.PartNumber = tblRevRelLog_Detail.PartNumber)
AND (tblEventLog.PartNumberChgLvl = tblRevRelLog_Detail.ChangeLevel)
WHERE ((([tblRevRelLog_Detail]![RevRelTrackingNumber]) =
[Forms]![frmEventLog_Input]![TrackingNumber]))
AND ((tblEventLog.PartNumber) NOT IN
(SELECT tblEventLog.PartNumber FROM tblEventLog
WHERE tblEventLog.EventTypeSelected = 'pn REMOVED From Wrapper'
AND tblEventLog.TrackingNumber =
tblRevRelLog_Detail.RevRelTrackingNumber
AND tblEventLog.PartNumber = tblRevRelLog_Detail.PartNumber
AND tblEventLog.PartNumberChgLvl =
tblRevRelLog_Detail.ChangeLevel
));
DISTINCT keyword for EnteredBy, EventTypeSelected is not working..I mean, data for these columns is not displaying when I use DISTINCT keyword.
EVENTDATE is working fine, but I do not understand why is it not displaying for EneteredBy and EventTypeSelected columns.
Can anyone tell me how to handle this?
It may be that the query can't interpret properly from the form directly as the final data type. However in your date field, you are wrapping it in a function CDATE( ... ). So, the SQL engine knows the result type. I would suggest doing the same for the other fields. Ex: doing a CAST ( ...your form control... as DateTime ) as OtherColumn, etc... I THINK Access allows casting, but not positive. Otherwise, pre-pull the form value into a declared data type variable and use THAT variable in the query AS OtherColumn as you are doing.
Additionally to what #Jack mentioned, you can always go back to your account, look at your historical question, and click on whatever answers actually helped / solve your problems. Some questions never do get answers and that's ok, just give credit to those that DO help.
I have found in the past (I don't remember which old version of Access this was) that if you set the value of a form control in VBA, and then use that control in a query, the query will not see the value you set in VBA. If the user edits the control normally, the query sees the expected value. Perhaps that's what happened here.
To work around that, you can declare a VBA function that returns the desired value. For example, instead of this:
SELECT ..., Forms!MainForm!TextEntry AS TextEntry, ... FROM ...
use this:
SELECT ..., GetTextEntry() AS TextEntry, ... FROM ...
along with this:
Public Function TextEntry() As Variant
TextEntry = Forms!MainForm!TextEntry
End Function