"Kathleen Turner" <kt*****@visuallink.com> wrote in message
news:vn************@corp.supernews.com...
I have an Excel file that has list of serial numbers followed by a 4 digit
code. I have an Access database that has the serial numbers but the field
for the 4 digit code is either blank, has the 4 digit code, or contains 4
X's.
What I would like to do is go through each record in Access, check the
serial number and then compare that serial number with the one in the
Excel spreadsheet. If the serial number in Access has a NULL value or a string
of four X's then I would like extract the 4 digit code from the Excel
spreadheet and populate the 4 digit code in the corresponding field.
Can I do this with VB and Access? How difficult do you professionals
think this might be. I am only a novice programmer.
I hate to think of doing this by hand.
Me too!
You seem to be mixing up your terminology, in your 2nd para you talk about
the serial number in Access being null or a string of 4 X's. Do you mean the
code? I assume you do.
You've got:
Excel file:
serial# code
100302 2435
349098 3458
etc.
Access table
serial# code
100302 NULL
349098 3458
324554 XXXX
etc.
Yes? And once this stuff is all into Access then you can discard the Excel
file?
First of all get you Excel table into Access. In Access File/Get External
Data/Import. You'll get a wizard asking you questions about how you want to
import. I don't know what the format is in Excel, so do you best there.
Anyway you'll end up with a new table in Access.
So you've now got 2 tables. I'll call them accessData and excelData. Make a
new query. Add those two tables. Join them on serial#:
SELECT accessData.[serial#], accessData.code, excelData.[serial#],
excelData.code
FROM accessData INNER JOIN excelData ON accessData.[serial#] =
excelData.[serial#];
Make sure the records 'line up' how you expect.
Change the query to an update query. And change the SQL to this:
UPDATE accessData
INNER JOIN excelData
ON accessData.[serial#] = excelData.[serial#]
SET accessData.code = [excelData].[code]
WHERE (((accessData.code)="xxxx")) OR (((accessData.code) Is Null));
You don't have to run it yet. Click the datasheet icon to see what WILL be
changed when you do run it. OK? then run it (Query/run). Change it back to
the first SELECT query. Does that look like what you expected?
That's if I've understood what you want. I'd strongly advise you to do all
this on a copy of the database first. There are all sorts of questions about
the data too. Is serial# unique? Are you sure that the only values in code
are a valid code, "xxxx" or null? If serial# is unique (or meant to be) then
I'd set unique a unique index on it to make sure.
HTH, Mike MacSween