I have an Access table "results" that contains assay lab results for different analytes. I have a second table "results_final" that will contain all the cleaned up values. Cleaning the results occurs in scenarios such as different labs providing results in different ways when analytes are not detected, for example with the use of the "<0.0001" (less than) others use an "X" and so forth. I want to appended the results_final table so that the results for analytes that are detected are kept the same and those that are not detected are changed to "-999999" so that they are consistent (and numerical) in the "results_final" table. This might occur across multiple cells for multiple records.
I have use a simple query to identify records that would qualify such as
'''select * From results where result_value '<' '''
Where I am stuck is using the append to update the 'Results_final' table to insert the desired value.
This will be an ongoing requirement so ideally I need to be able to repeat/automate the process easily.
What is the best approach to change/append all the records that meet the specific requirements?
I would probably just update field in same table. Something like:
CurrentDb.Execute "UPDATE table SET field1=-999999 " & _
" WHERE field0 IN('<0.0001', 'X', 'XX', '-0.0001')"
Or
CurrentDb.Execute "UPDATE table SET field1=-999999 " & _
" WHERE Not IsNumeric(field0)"
Or
CurrentDb.Execute "UPDATE table Set field1=IIf(IsNumeric(field0), field0, -999999) WHERE field1 Is Null"
Related
Yesterday I asked a similar question, and thank you to those who replied. I'm creating this new question as I've worked a few things out and can hopefully provide more/better information, but still running into the same problem. I'm very, very new to Access and any kind of code or related terms so thank you in advance for your patience with me.
I'm building a query to search tbl: Inventory. There are no lookups built into the table. The parameters can be entered via combo boxes on a form by the user. The row sources for the combo boxes are distinct values from the coordinating fields in tbl: Inventory. I want the user to be able to fill in any/all parameters and get results, so I'm using LIKE "*" in my criteria of each parameter. All values in the parameters are text. In tbl: Inventory the fields are also all text (except the PK which is an autonumber). This is my SQL for the query:
SELECT Inventory.InventoryID, Inventory.SetID, Inventory.ItemName, Inventory.Period, Inventory.Color, Inventory.GarmentType, Inventory.GarmentSubType, Inventory.ATCShow
FROM Inventory
WHERE (((Inventory.Period) Like "*" & [Forms]![frmSearchInventory]![cboPeriod] & "*") AND ((Inventory.Color) Like "*" & [Forms]![frmSearchInventory]![cboColor] & "*") AND ((Inventory.GarmentType) Like "*" & [Forms]![frmSearchInventory]![cboType] & "*") AND ((Inventory.GarmentSubType) Like "*" & [Forms]![frmSearchInventory]![cboSubType] & "*") AND ((Inventory.ATCShow) Like "*" & [Forms]![frmSearchInventory]![cboShow] & "*"));
Please excuse the excess brackets, as I said, very new so I'm letting Access do most of the writing for me.
For some reason, no matter what combination of parameters are used, it will not return any records where Inventory.GarmentType = suit coat, and the record also includes a SetID--even if the only parameter entered is "suit coat". For records that do not include a setID and are type=suit coat, the record is returned. If the record includes a setID and is not a suit coat, the record is returned. Not sure if that is related, as SetID is not a parameter, but it's something I noticed.
I've tried changing "*" to "%" and LIKE to ALIKE and no records at all were returned.
Any ideas? Happy to provide any additional information. Thank you!
Hi I've searched the net and couldn't find the right answer to my question.
I have two tables GCSALLDATA and GCS-RECONCILED. They both have the same columns but I only need to focus on two [Control Number] (Short Text) and [NotInDevTrack] (yes/no)
I want to search GCSALLDATA for the Control Number found in GS-RECONCILED. If it's found Update the record.
From what I read using a DCOUNT should be able to do this, but wondered how would it cycle through all the records in the table?
Here is my attempt at using to use it
If DCount("[Control Number]", "GCSALLDATA", "Control Number=" & [GCS_Reconcile].[Control Number]) > 0 Then
MsgBox ("Control number already in use")
Else
MsgBox ("Control Number missing add it")
End If
Assuming I've correctly understood what you mean when you state:
I want to search GCSALLDATA for the Control Number found in GS-RECONCILED. If it's found Update the record.
You can use a simple update query to update records in GCSALLDATA for which there is a matching Control Number in GS-RECONCILED, for example:
update GCSALLDATA t1 inner join GS-RECONCILED t2 on t1.[Control Number] = t2.[Control Number]
set t1.NotInDevTrack = True
Assuming that you wish to set the NotInDevTrack field to True (Yes) for those numbers which match.
First and foremost, thank you for your time in reviewing my post and offering your advice. I have a database with the following schema:
tblPR:
PRID
Title
Amount
Status
tblProgram:
ProgramID
ProgramCode
ProgramTitle
tblFund:
FundCodeID
FundCode
FundTitle
There’s a many to many relationship between the previous two tables. Therefore, I setup a junction table.
tblPrgFund:
ProgramCode
ProgramTitle
FundCode
FundTitle
(These are lookup fields to their respective tables so I believe Access pulls their key as well which would be the ids)
Now main form is set to tblPR and subform is set to tblPrgFund. There are two comboboxes in subform for FundTitle and ProgramTitle respectively. Requirement is to filter ProgramTitle based upon FundTitle that is selected by user.
To do this I tried the following SQL command in VBA for gotfocus event of program title combo box. But it is only displaying ProgramID and not ProgramTitle. I don’t even think the ids are correct tbh.
"SELECT ProgramID, ProgramTitle FROM tblPrgFund WHERE FundCode = " & Me.FundCode
If I am understanding your dilemma correctly, you want something like this:
"SELECT ProgramTitle FROM tblPrgFund WHERE FundTitle = " & Me.FundCode
OR (if you wanted to use the FundCode, and not the FundTitle)
"SELECT ProgramTitle FROM tblPrgFund WHERE FundCode = " & Me.FundCode
NOTE: This assumes that your FundCode and FundTitle are unique values in your data. But you shouldn't be grabbing the ProgramId, unless your intention is to use it in some way.
That being said, I would highly suggest you use After Update instead of GotFocus as your event for this type of update. Since this is a drop down box, I would assume you don't want the updates to go just from the initial selection of the Combo Box, but rather start after a selection has been made.
I am dealing with approximately one dozen MS access tables that are all linked into a single database file.
Occasionally I would like to be able to get the union of these tables to generate a complete dataset. My attempts to do this so far result in a too many fields defined error.
Is there a way for me to do this using Microsoft access (I can use 2007 or 2010 versions)? If not, any other suggestions on how this could be achieved would be greatly appreciated.
According to the "QUERY" section of the "Access 2010 Specifications" topic in Access help, you are limited to 255 fields (columns) per recordset (query). If the "complete dataset" you want to produce will have more than 255 columns then you won't be able to do that in a single Access query.
One possibility might be to create several queries with no more than 255 columns each, export them to Excel, then paste them together side-by-side into a very wide Excel document. Excel_2010 worksheets can have up to 16,384 columns. It could be a bit tedious to do manually but there would be some opportunity to automate the process, at least in part. You'd also have to be careful that each "partial query" returned the same number of rows in the same order so things would "line up" when you pasted them together.
This answer is about a different occurrence of the "Too many fields defined" error from a query, and what I did to eliminate it.
I have a query that was giving me that error. Compacting the database didn't fix it. When I split the query into three queries with fewer fields in each, two of those smaller queries worked okay, but one still gave me the error. So it appeared that the problem had nothing to do with the number of fields, but with something about the coding of the query.
The query had two similar fields coded as subqueries:
(SELECT first([Date]) FROM [C:<path>\sources.accdb].[items - subjects] WHERE [Subject name] = SubjName and Assessment like "*Buy*") AS FirstBuyRecDate
and
(SELECT first([Date]) FROM [C:<path>\sources.accdb].[items - subjects] WHERE [Subject name] = SubjName and Assessment like "*Sell*") AS FirstSellRecDate
The error first arose when the second of those fields was added to the query. The query was able to work with either of those fields present, but not both. It was also able to work if the subquery in either of the fields was replaced with a random date constant, such as #2018 12 31#. So it appeared that the problem had something to do with those subqueries.
I was able to eliminate the error by changing those subqueries to function calls using a UDF I had previously developed for another purpose:
Public Function vFtnInQry(sField As String, sSQL As String) As Variant
' Return the value of the field with the name <sField> in the select query <sSQL>.
' The purpose of this is to allow inserting a variable value into the SQL of a query.
Dim oRecSet As DAO.Recordset, nCountRecords As Long, vRetVal As Variant
Set oRecSet = CurrentDb().OpenRecordset(sSQL)
nCountRecords = oRecSet.RecordCount
If (nCountRecords = 0) Then
vRetVal = Null
Else
vRetVal = oRecSet.Fields(sField).Value
End If
vFtnInQry = vRetVal
End Function
So the field definitions changed to:
vFtnInQry("BuyRecDate", "SELECT first([Date]) as BuyRecDate FROM [C:<path>\sources.accdb].[items - subjects] WHERE [Subject name] = """ & [SubjName] & """ and Assessment like ""*Buy*""")) AS FirstBuyRecDate
and
vFtnInQry("SellRecDate", "SELECT first([Date]) as SellRecDate FROM [C:<path>\sources.accdb].[items - subjects] WHERE [Subject name] = """ & [SubjName] & """ and Assessment like ""*Sell*""")) AS FirstSellRecDate
I don't know why this solved the problem. I'm posting it here in case someone else has a mysterious occurrence of "Too many fields defined" from a query that might be solved this way. On the other hand, if someone reading this sees a reason that those subqueries were causing that error, please post about that in a comment or another answer.
very simple one. I have got two fields in a table called [First Name] and [Last Name]. I would like to add a new column that is just a combination of [First Name] and [Last Name] - is there a way to do this in Access? I know this can be done in Excel using the Concatenate function.
I would like to do this in the existing table and not in a new query.
Thanks!
As #paxty says, do not do this. You have a simple answer in Access that is not available in Excel, and that is a query. You can base any output that requires that the two names be concatenated on a query.
SELECT FirstName & " " & LastName FROM MyTable
In Access 2010 you can create a "calculated field" for your table; Access applies a formula to create the content of the field. You can enter a formula such as:
FirstName & " " & LastName
You could even do fancier things like have an initial then the last name, if there is a last name, or else show the complete first name, using the Access IIf() and Len() functions.
IIf (Len(LastName) > 0, Left(FirstName, 1) & ". " & LastName, FirstName)
By using a calculated field to join the two names directly in the table... It creates issues down the road. I have two fields First & last name I used a calculated field in the table to join the two together. When you try do a report with those calculated names, it will show only the employee number, not the names. Now I am trying to correct my mistake without having to rebuild the multiple tables I have used this field as a look up in.