Write from Excel to Access multicolumn combobox field using VBA - excel

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.

Related

Filter Access Table based on External List

I have a table called "Inventory", which contains all the "Items" (physical parts, components).
I have another table, called "Products", where the main products are listed.
A third table is "Manufacturing Orders".
Every time a new manufacturing order is in production i'd like to get this two effects:
The quantity in stock for the selected Products increase
The quantity of the items which made the Product up decrease of their specific units.
Of course to do this i need a BOM.
I'm trying to figure out the most efficient way to generate a BOM.
The solution I've thought about so far is the one as follow:
Every time there is a new Manufacturing Order, filter the Inventory table based on an External list (on Excel), and decrease the qnt just for the items available in the "Filtering list".
I'm wondering if there is some function in Access which allows this or i do need VBA.
Also, if there is a more quick and efficient solution.
Note: i decided not to create the bom as tables to keep the db more clean.
Thanks in advance
I would first determine from which application are you controlling this update; from within Access retrieving the data from Excel, or within Excel updating the tables in Access?
If you are within Access you could pull the data into a record set in a manner such as Query Excel worksheet in MS-Access VBA and then using the rs2.field(***).value to build a Access-SQL UPDATE string to update the table. This could be placed in a form that drives the VBA code. Note that within the referenced hyperlink there is a function fncOpenFile. This is most likely a file dialog procedure to retrieve the filename. A similar function is this:
Private Function GetFileName() As String
Dim FO As Object 'file object
Set FO = Application.FileDialog(3)
With FO
.allowMultiSelect = False
.show
GetFileName = .SelectedItems.Item(1)
End With
End Function

MS-Access Automatically updating data based on another table (Email Blacklist)

I'm setting up a brand new database as a lot of the work we do is on multiple spreadsheets and a lot of the data is duplicated. I have a lot of knowledge with Excel, however, I feel that Access would much better suit the needs of the business and data management.
A large role for many in the business is to send emails/follow-up emails based on criteria, however, we use several services to do this and I need a new method of tracking people/businesses who have 'Opted-out' of email updates, we can export the people who opted out from the different applications and put into a spreadsheet.
I had a little play around with relationships to see if this would work, however, kept getting error along the lines of 'invalid for field type' and although I could do this with a simple countif function in Excel I was wondering if it's possible in Access without VBA.
One of the fields we have for our sponsors/delegates table is email address. I want to know if it is possible to create a new form & table or something to do the following:
User loads form, clicks a button and selects spreadsheet with emails in Column A
Data from column A is then imported into a blacklist table
Access removes duplicates and adds the rest to a blacklist table
Access updates sponsor/delegate table field 'opt-out' to yes for any email addresses added to the blacklist table
Edit: Here are 2 screenshots of the separate tables
What I need Access to do is basically tick the box 'opt-out' automatically for all records where the email matches to one in the blacklist
A query to update the opt-out field in your Sponsors table for all records which have a matching email address in the Blacklist table is relatively straightforward, with the matching operation performed by a single inner join, e.g.:
update Sponsors inner join Blacklist on Sponsors.[Email Address] = Blacklist.[Email Address]
set Sponsors.[Opt-Out] = -1

Updating A Filemaker Database From An Imported List

I have a large Filemaker 12 database with current inventory items, about 100 fields per record and about 10,000 records. Physical inventory is currently done by hand. What I would like to do it with a bar code scanner which spits out an ASCII list of serial numbers separated by carriage returns.
What I need to figure out is: how to write a script taht will import the list of serial numbers we have scanned into another table, and then one by one match the serial number in the import table to a serial number in inventory, and then enter a check mark or text (present for example) into a new field in the inventory table which will let me know that it is present.
You might consider expanding your question to include more details about how you are trying to implement your solution, the tables you already have, and the relationship between them.
One way to use a barcode scanner to update text on your inventory table would be as follows:
Create a new table, we'll call this one barcode scans
On the table, create a text field, we'll call this serial numbers
When you create the table 'barcode scans' a table occurrence (also called 'barcode scans') should be created for you in the Relationships diagram in Manage Database.
Create an = relationship between barcode scans::serial numbers and inventory::serial number
Create a layout for the table occurrence of barcode scans
On the layout place the text field barcode scans::serial numbers
With the barcode scanner it sounds like you will get a return-delimited list of serial numbers in this field if you start scanning into it.
Create a script, we'll call it Mark Items Present
The first step of Mark Items Present is Go To Related Records. Set the options to show only related records and only for the current record. Have it go to your inventory layout. Due to the multi key relationship you set up in step 4, this will find all of the indices in inventory that were scanned in barcode scans.
The second step of the Mark Items Present script is Replace Field Contents. Set it to the field you want to fill with "present" and set the calculation to "present". This will mark all of the records in the found set (which should be only the scanned records because of the step above) with "present".

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);

Updating a table Access and Excel VBA

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!

Resources