The following syntax is not working in MS Access SQL view. Basically I have two columns: 1) Rejection Reason 2) Last AP User. And I'm trying to remove from the table anything where there is a word import under rejection reason and renukesha and nagesha under Last AP User column. Code runs perfectly but the rows are not removed from the data table.
Here is my code:
((Switch([DFM report].[Rejection Reason] like "%Import%" And [Last AP User]
ALike "%renukesha%",1,[DFM report].[Rejection Reason] like "%Import%" And
[Last AP User] ALike "%nagesha%",1,[DFM report].[Company Code] not like
"%Import%",1,True,0))=1)
Related
I have created a form where when an item is clicked, data about that item is displayed. This is a situation in which the [Index] within a certain item was created in the form of spraying it on the subform.
However, when I put my table in access in "From statement", it works, and when I put my query in access, it doesn't work. Is the query within access difficult to utilize in the From statement? I wonder what the reason is.
In the case of B (query), it is a query made with the items of A (table) and C (table).
error O)
Me.ABCD.Form.RecordSource = "SELECT * FROM B(query within access) WHERE ([index]=[Forms]![EFG]![lst]);"
error X)
Me.ABCD.Form.RecordSource = "SELECT * FROM A(Table in Access) WHERE ([Index]=[Forms]![EFG]![lst]);"
I have a table tblItems with a list of inventory items. The table has many columns to describe these items, including columns for SupplierName, SupplierOrderNumber and PredictedArrivalDate.
If I order several new items from a supplier, I will record each item separately in the table with the same supplier name, order number and a predicted arrival date.
I would like to add a data macro, so that if I update the PredictedArrivalDate for one record, the value will be copied to the PredictedArrivalDate column of other records/items with the same SupplierName AND SupplierOrderNumber.
The closest I've got is:
SetLocalVar (MySupplierName, [SupplierName])
SetLocalVar (MySupplierOrderNumber , [SupplierOrderNumber ])
SetLocalVar (MyPredictedArrivalDate, [PredictedArrivalDate])
For Each Record in tblItems
Where Condition = [SupplierOrderNumber] Like [MySupplierOrderNumber] And [SupplierName] Like [MySupplierName] And [PredictedArrivalDate]<>[MyPredictedArrivalDate]
Alias OtherRecords
EditRecord
SetField ([OtherRecords].[PredictedArrivalDate], [MyPredictedArrivalDate])
End EditRecord
However, when I run this, only 5 records update, and the error log reports error -20341:
"A data macro resource limit was hit. This may be caused by a data
macro recursively calling itself. The Updated() function may be
used to detect which field in a record has been updated to help
prevent recursive calls."
How can I get this working?
I'm not one for using macro's to do anything, so I'd use VBA and recordsets/an action query to do the updating.
You can call a user-defined function inside a data macro by setting a local var equal to its result.
Access doesn't like data macros triggering themselves (which you are doing, you're using an on update macro and updating fields in the same table on a different record), because there is a risk of accidentally creating endless loops. Looks like you triggered a measure that's made to prevent this. I'd try to avoid that as much as possible.
Note: using user-defined functions inside data macros can cause problems when you're linking to the table from outside of Access (via ODBC for example).
This isn't a good solution (it's not a data macro), but it does work as a temporary fix.
I created an update query called "updatePredictedArrivalDate":
PARAMETERS
ItemID Long,
MyPredictedArrivalDate DateTime,
MySupplierName Text ( 255 ),
MySupplierOrderNumber Text ( 255 );
UPDATE tblItems
SET tblItems.PredictedArrivalDate = [MyPredictedArrivalDate]
WHERE (((tblItems.SupplierName) = [MySupplierName])
AND ((tblItems.SupplierOrderNumber) = [MySupplierOrderNumber])
AND ((tblItems.ID) <> [ItemID]));
On the PredictedArrivalDate form field .AfterUpdate event, I then added this macro:
IF [PredictedArrivalDate].[OldValue]<>[PredictedArrivalDate] Or [PredictedArrivalDate]<>""
OpenQuery (updatePredictedArrivalDate, Datasheet, Edit, [ID], [PredictedArrivalDate], [SupplierName], [SupplierOrderNumber])
I now have to remember to add this .AfterUpdate event to any other forms I create that amend that particular field.
If anyone has a better solution, please let me know.
I have created a database with the intention of allowing analysis of patients blood test results for a certain condition. The query itself is working fine however is unsearchable (in other queries i've generated I've identified this is was because I had spaces in the headings and so removed these)
This query is now duplicating patients for each positive test they have from the selection. This seems to be linked to the .value column as goes away when this is removed however then the query becomes unsearchable using the quick search tool.
Is there any solution to this? I'm using the query wizard to build these. Believe the problem is with the 'OtherImmunology.Value' part
SELECT cci.rq6number,
pi.firstname,
pi.lastname,
pi.nhsnumber,
pi.dob,
Datediff("yyyy", [dob], [initialdiagnosisdate]) AS AgeAtDiagnosis,
pi.gender,
pi.[diagnosis(iapconsensuscriteria)],
cci.initialdiagnosisdate,
cci.steroidtherapy,
cci.responsetosteroids,
cci.igg4level,
cci.[igg4actualresult(mg/dl)],
cci.serumigg,
cci.[serumigg result(g/l)],
cci.otherimmunologytested,
cci.otherimmunology,
cci.** otherimmunology.VALUE,
cci **.[ca19-9level],
cci.[ca19-9actualresult(ku/l)],
cci.surgery,
cci.otherautoimmuneconditions,
cci.autoimmunecondition,
cci.completed
FROM [patient information] As pi
INNER JOIN [Clinical Contact Informtion] As cci
ON pi.[rq6number] = cci.[rq6number];
I have a sub in Access 2010 that references a query. They're supposed to run through three columns and find the lowest one. When I run it, I get an error: "The expression you entered as a query parameter produced this error: 'Projects.ProjectID'
Sub:
Private Sub UpdatePriority_Click()
Overall_Priority = DMin("MinvonGeoPri", "qryOverallPriority", "Projects.ProjectId=1")
End Sub
Query:
SELECT
Min(Projects.GeoPavePri) AS MinvonGeoPri
, Min(Projects.StrPri) AS MinvonStrPri
, Min(Projects.SOPri) AS MinvonSOPri
, Projects.ProjectId
FROM
Projects
WHERE
Projects.ProjNo=Activity.ProjNo;
Google suggested that I add quotations around 1, so I changed it to "Projects.ProjectID=" & 1 & "", but it didn't help. I've double checked spelling, field names, and I'm running out of ideas. Any suggestions would be great.
Once you have created a qryOverallPriority from the select statement, referencing the Projects.[ProjectId] field is simply [ProjectId]. In short, you lose the ability to reference the parent table although it could be referenced as qryOverallPriority.[ProjectId] but that is not necessary..
Private Sub UpdatePriority_Click()
Overall_Priority = DMin("MinvonGeoPri", "qryOverallPriority", "ProjectId=1")
End Sub
Any field pulled by a saved query is referenced by how that save query sees it, not from the underlying SQL select statement that made up the saved query. Likewise, aliased fields would be referenced by their aliases; e.g. [ProjectId] and [ProjectId2] for both [ProjectId] fields in a join.
You are also using the aggregate MIN function without a GROUP BY clause. Use the Access front end to make sure that you are getting the results you want. Perhaps something like,
SELECT
Min(p.GeoPavePri) AS MinvonGeoPri
,Min(p.StrPri) AS MinvonStrPri
,Min(p.SOPri) AS MinvonSOPri
,p.ProjectId
FROM
Projects p
WHERE
p.ProjNo=Activity.ProjNo;
GROUP BY p.GeoPavePri, p.StrPri, p.SOPri, p.ProjectId
You should be able to use,
Overall_Priority = DLookup("MinvonGeoPri", "qryOverallPriority", "ProjectId=1")
That is untested. I have not built a full test environment and I have no idea where Activity.ProjNo comes from.
Within my Access 2010 form I have the ability to add records, but before one adds a record, we need the ability to check if the business unit, year, and quarter already exists within the SQL table before new record is being written.
The three things I need to confirm are the fields in my form called [BU_Selected_Add], [Qtr_Add] and [Year_Add] in the SQL table "tTbl_ADMIN_RxREBATE" within their respective fields:
[GL_BU], [Year], and [Quarter].
So I started with a simple Business_Unit dlookup below:
If DLookup("[GL_BU]", "tTbl_ADMIN_RxREBATE", "[GL_BU] = '" &
Me!BU_Selected_Add & "'") > 0 Then
MsgBox "This Business Unit already exists within the data below!"
I get the following error:
Run-time error '3078': The Microsoft Access database engine cannot find the
input table or query "tTbl_ADMIN_RxRebate". Make sure it exists and that its
name is spelled correctly.
It most certainly exists in the SQL Server 2008 R2.
I need to get this first part right before adding in whether that [BU_Selected_Add] was added during the year and quarter within the fieldboxes called [Qtr_Add] and [Year_Add].
SELECT dbo_tTbl_ADMIN_RxREBATE.MSID, dbo_tTbl_ADMIN_RxREBATE.DateAdded, dbo_tTbl_ADMIN_RxREBATE.Qtr, dbo_tTbl_ADMIN_RxREBATE.Year, dbo_tTbl_ADMIN_RxREBATE.Rpt_Date, dbo_tTbl_ADMIN_RxREBATE.SRVC_TYP_CD, dbo_tTbl_ADMIN_RxREBATE.GL_BU, dbo_BU_Description.[BU Description], dbo_tTbl_ADMIN_RxREBATE.PY_FNL_PICK_AMT, dbo_tTbl_ADMIN_RxREBATE.PY_FNL_MRGN_AMT, dbo_tTbl_ADMIN_RxREBATE.PY_IBNR_AMT, dbo_tTbl_ADMIN_RxREBATE.CY_FNL_PICK_AMT, dbo_tTbl_ADMIN_RxREBATE.CY_FNL_MRGN_AMT, dbo_tTbl_ADMIN_RxREBATE.CY_IBNR_AMT
FROM dbo_tTbl_ADMIN_RxREBATE INNER JOIN dbo_BU_Description ON dbo_tTbl_ADMIN_RxREBATE.GL_BU = dbo_BU_Description.BU
WHERE (((dbo_tTbl_ADMIN_RxREBATE.Qtr)=[Forms]![Frm_Main]![Frm_Main_Combo_Qtr]) AND ((dbo_tTbl_ADMIN_RxREBATE.Year)=[Forms]![Frm_Main]![Frm_Main_Combo_Year]));