Intelligent Comparison based Update - Access / VBA -
need intelligently perform updates on access table. expert vba / intelligent thinking required.
table1 (for reference only) companycode text regioncategory number (1-99) regioncount number(0 - 25000) table2 invoicenumber number companycode text numrows number regioncode fourdigitnumber confirmationremark y / n
ourobjective put yes or no in 'confirmationremark' column. rules :
1.select invoicenumbers have 2 rows table2 , different regioncode. these have same companycode. regioncategory first 2 digits of regioncode.
2.for these 2 invoices - difference between 2 regioncategory must greater two.
3.lookup regioncount , table1
decision making : comparing 2 invoices different regioncodes. idea , invoice higher regioncount 1 marked yes.
1.the difference between regioncount must considerable. 'considerable' - trying determine right number. let take 500 now.
2.the invoice lower region count - should have regioncount - 0 (bestcase) or very low. if invoice lower region count has high regioncount value > 200 , cannot conclude.
3.numrows , prefered 1 or lesser other. comparison , not mandatory , hence shall have provision not check this. mark other invoice 'n'
you have many ways approach type of complex update.
if lucky, may able craft sql update
statement can include changes, have resort combination of select
queries , custom vba filter them based on results of calculations or lookups involving other data.
a few hints
often, tend think problem in terms of 'what steps data match criteria'.
sometimes, though, it's easier turn problem on head , instead ask 'what steps data not match criteria'.
because in case result boolean, true or false, setconfirmationremark
fieldtrue
records , update should setfalse
, instead of other way around.break down each step (as did) , try find simplest
select
query return data need step. if step complex, break down further.compose broken down
select
statements build more complex query tends toward goal.once have gone far can, either construct
update table2 set confirmationremark=true invoicenumber in (select invoicenumber ....)
or use vba go through recordset of results complextselect
statement , more checks before update field in code.
some issues
unfortunately, despite efforts document situation, there not enough details help:
you not mention primary keys (from say, seems
table2
have multiple records identicalinvoicenumber
)the type of data dealing not obvious. should include sample of data , identify ones should end-up
confirmationremark
set.your problem localised, meaning specific of value else, although think bit more details question of interest, if show example of how approach complex data updates in access.
Comments
Post a Comment