Updating a table Access and Excel VBA - excel

I have one table called: Transaction. This table has the following fields: (ID,ProductName,Amount,Date) placed in an excel sheet that is connected with MS Access database. ID is the only unique field. Sometimes, my user submits a transaction that has let's say 5 records. Then, they want to modify the submitted data in case if they entered incorrect amount and they want to correct it. I want to write a code in VBA that will do the update. my current query is:
Update table Transaction(ProductName,Amount) set ProductName=#Product,Amount=#Amount)
where Date=#date;
This query does not work fine because obviously it replaces all the records data with the data of the last resubmitted record because my condition is weak. My difficulty is that I can't find a good condition in the where clause that will do the update a record by record accordingly.
Please help,

You will need to use the unique id of the record, in your case the ID field to guarantee you are updating the correct record.
Something like the following:
Update table Transaction(ProductName,Amount) set ProductName=#Product,Amount=#Amount) where ID = "id of record you want to update"
Enjoy!

Related

Write from Excel to Access multicolumn combobox field using VBA

I have an Access file with two tables: users & products. Users keeps a list of who can write to the Access file (fields like userID, systemID, name). Products keeps a list of product attributes including who made the last update to the record. The last update field is a combobox with two columns: userID (bound to this), name (displays this due to column widths of 0";2").
I also have an Excel file, named simulator. Using VBA, the simulator reads from the products table, uses assorted prediction algorithms to simulate the product's future, then writes the predictions back to Access.
When Excel writes back to a product's record, I'd like to record the last update author to be simulator. Assuming this user exists (userID=100, name=Simulator, say), how do I do this?
I currently have
' Open Access database, get products table, get product record
connection.Open ...
products.Open "Products", connection, ...
products.Filter = "ProductID = " & productNumber
' Update record
products("LastUpdateAuthor") = "100; Simulator"
products.Update
products.Close
And this writes "100; Simulator" to the correct field. How do I get it to recognize that 100 is the bound column and Simulator is the second column?
Should only save the UserID into LastUpdateAuthor field. Then multi-column combobox RowSource should be an SQL statement of Users table in order to retrieve and view the related UserName. So have a record in Users with UserID 100 and name Simulator, then still just save the UserID.
As long as the RowSourceType is Table/Query, it will see the 100; Simulator value as a single string from the LastUpdateAuthor field. Can set combobox RowSourceType as ValueList then use code manipulating recordset and Add method to load the LastUpdateAuthor data to the RowSource and the semi-colon will be recognized as column separator. However, if you do as described in first paragraph, this should not be necessary.

Mongoose How to update if exists, based on custom fields. Otherwise insert

I'm building a mongoDB database that holds sales data from multiple different systems. Each system is integrated via an node/mongoose/Express API that I'm creating for the database. Typically, you'd check the id to determine if a record already exists, and insert it if it doesn't. But since the ID from these different sources could technically overlap, I need a system to make sure that a source can only update records that originally came from that source. So I've added a column called "external_ID" where the record id from the source is saved, and another column called "integration ID", which will be unique to the specific system that sends data. But for that idea to work, I'd need to update only if those two columns matches, and otherwise insert a new record. Is that possible with MongoDB, or am I approaching this wrong?
Thank you so much.
Use upsert on update(). It will creates a new document when no document matches the query criteria.
db.collection.update(<query>, <update>, { upsert: true })
You can find more detail at Upsert Behavior documentation

How to insert data in azure easy table?

I want to insert the data in a specific column of azure easy table with xamarin forms.i already insert the data in a row but some fields are empty and these can be fill later by the user when user want to update the record.
for example there is a table which name isUSER(User-id,UserName,Email,Password,Mobile-No) user enter all data except MobileNo and it may or may be entered first time but may enter later.if they enter mobile number later then how I do that ?
First of all , All CRUD are operated on the object in Azure easy table .If you create this record at the first time, You could insert this record to Azure easy table. If user want to add the mobile number in the next time, you could query this record, then delete the old data, put the new record to the table.
You could refer to following link.
https://officialdoniald.azurewebsites.net/2017/02/24/xamarin-forms-azure-easy-table-accsess/
If you want to know more basic knowledge, you can refer to the link below
https://blog.xamarin.com/getting-started-azure-mobile-apps-easy-tables/

Adding a field to a table that is the result of a query to another table

In MS Access 2010, I have two tables - one with Candidates and one with Package Actions. The Actions are associated with the Candidates via the CandidateID field, which is an autonumber in the Candidates table. The Actions table has a date field for each action. I have a field in the Candidates field that I would like to display the action type of the most recent action associated with that particular candidate, but can't seem to figure out how to do it. I've tried implementing a subquery as a default value:
SELECT TOP 1 ActionT.ActionType FROM ActionT WHERE
(((ActionT.CandidateID)=13))
ORDER BY ActionT.DateCompleted DESC;
Obviously, this query on its own only returns the most recent action for candidate 13 but ideally I would like to replace the =13 with =CandidateID but I can't even get the field to populate with the result of the query as is. I've also tried using DLookup but got an error while trying to make that the default value. I've also tried using the button "Modify Lookups", pasting the query and the DLookup directly into the cell, and trying to change the type of the field from "Text" to "Calculated", all to no avail.
Novice MS Access user here, so I appreciate any extra explanations y'all may have.
Thanks In Advance.
EDIT:
Just to be clear, I'm not looking for a query, per se. I want to know how I can make the result of my query above always be the value of a field in the candidate table. (If my code above needs corrections, I'm open to that, but that isn't really my question.)
Example: Candidate A has several actions in theActionTable associated with him. They are ResumeRecieved, ResumeReviewed, and Interviewed. The date associated with Interviewed is the most recent, therefore in the CandidateTable, the status for Candidate A should be "Interviewed." We then decide to extend an offer, so we add an action to the ActionTable "OfferExtended."
The Status field in the CandidateTable for Candidate A should automaticaaly update to read "OfferExtended"
Inside your main SELECT STATEMENT, you need to have a nested SELECT STATEMENT descendingly ordered by DateCompleted to get the most recent DateCompleted for each CondidateId.
Below should do the trick for you:
SELECT con.Id,
con.Name,
(SELECT TOP 1 ActionType FROM ActionT
WHERE CandidateId = con.Id ORDER BY DateCompleted DESC) AS ActionType
FROM Candidates AS con

Getting the greatest value for a field for all records

For our Employee records within NetSuite, we have a custom field called "Employee Number" with an ID of custentity1. I've created a workflow that will automatically create a new employee record and populate various fields but the one I'm having difficulty with is the Employee Number field. All I want to do is to grab the largest employee number there is out of all of the Employee records and add one to it for the new employee record.
The Employee Number field is a free-form text field so I know I'll have to use TO_NUMBER, but anytime I try and reference {custentity1} I keep getting an error saying that field is not found.
UPDATE: I've created a new custom field for our employee records called "Employee No." with an ID of custentity_employeenumber. I've also created a javascript file with the following:
function getMaxEmployeeNumber(){
var empNumber = nlobjSearchColumn('custentity_employeenumber', null, 'max');
return empNumber;
}
But how to do I get this to work with my records?
NetSuite does have an auto-numbering mechanism built in to its native functionality that most of our customers use for this exact purpose. Is there a special reason this functionality is not being leveraged? This functionality is accessible at Setup > Company > Auto-generated Numbers.
I do not work much with workflows, so I do not know if this same functionality is possible there, but here is how I would solve this in SuiteScript:
Create User Event script that is executed on Before Submit Create event for Customer records
Create a Customer search that has a Search Column for custentity1 with a summary type of max
new nlobjSearchColumn('custentity1', null, 'max');
Running this search should give you 1 result, which is the maximum customer number. You can then just add 1 to it.
You could create a similar Saved Search in the UI to see what the result set looks like.
This will only really work if the field is a Number, not Text. I would suggest changing the field to an Integer field if you know that it will always be a number. This may clear out existing data, so first you could export all customers and their number to Excel and then do a CSV import after changing the field.
How are you looking for the last employee in a workflow?
I know this can be done in js:
Search employees - returns max 1000
For number of employees give me the custentity1 of the last one - nlapiLookupfield('employee',employees[employees.length],'custentity1')
Add +1 and save on new record
If you use this search column
nlobjSearchColumn('custentity1', null, 'max');
You can also sort it in decreasing value so that the first result is always the max. Something like
nlobjSearchColumn('custentity1', null, 'max').setSort(true);

Resources