School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,419 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,498 people online right now. Registration is fast and FREE... Join Now!




Access Query

 

Access Query

sir.chunk

24 Jun, 2009 - 02:53 AM
Post #1

New D.I.C Head
*

Joined: 8 Dec, 2008
Posts: 7

Hi Guys and Gals,
I am wondering if it is possible to update a field in access, base on if another field in the same row matches a record in an excel sheet?
I'm using access 2000, and at the moment i can only do it if the data to check is in the same database.

Chunk

User is offlineProfile CardPM
+Quote Post


P4L

RE: Access Query

24 Jun, 2009 - 07:52 AM
Post #2

Geek 4 Life
Group Icon

Joined: 7 Feb, 2008
Posts: 2,163



Thanked: 16 times
Dream Kudos: 125
My Contributions
QUOTE(sir.chunk @ 24 Jun, 2009 - 02:53 AM) *

Hi Guys and Gals,
I am wondering if it is possible to update a field in access, base on if another field in the same row matches a record in an excel sheet?
I'm using access 2000, and at the moment i can only do it if the data to check is in the same database.

Chunk


Yes, it is possible.

You need to link in the Excel spreadsheet, or import it into the database that you are working with. Then have to join the fields, and run your query.

Without the code you are using, I can't help beyond that. The wizards, which is cheating, can help more when it comes to writing the update query.
User is offlineProfile CardPM
+Quote Post

sir.chunk

RE: Access Query

25 Jun, 2009 - 01:35 AM
Post #3

New D.I.C Head
*

Joined: 8 Dec, 2008
Posts: 7

QUOTE(P4L @ 24 Jun, 2009 - 07:52 AM) *

Yes, it is possible.

You need to link in the Excel spreadsheet, or import it into the database that you are working with. Then have to join the fields, and run your query.

Without the code you are using, I can't help beyond that. The wizards, which is cheating, can help more when it comes to writing the update query.


That's great, at least i now know i'm not wasting my time going down the wrong path.
I haven't done anything yet, but i am sure i will be back if i need more direction wink2.gif

Thanks for your help

Regards
Paul

This post has been edited by sir.chunk: 25 Jun, 2009 - 01:36 AM
User is offlineProfile CardPM
+Quote Post

sir.chunk

RE: Access Query

25 Jun, 2009 - 04:12 AM
Post #4

New D.I.C Head
*

Joined: 8 Dec, 2008
Posts: 7

Right i have now linked a excel sheet to the access database, and have successfully run a query that changes a feild if another feild on the same row matches a field in the excel sheet.

CODE
UPDATE Product, ExcelOOS SET Product.[Can be ordered online] = "0"
WHERE (([Product.Product Reference]= [ExcelOOS.Stk Code]));


The problem i have now is that there are some fields that i want change if it contains the text i am trying to check e.g. 1!A567A to change if it contains A567A.
I am trying to use the like command with not much success. I've tried in all different ways i can think of but it's not happening sad.gif

I've tried this (syntax error)
CODE
UPDATE Product, ExcelOOS SET Product.[Can be ordered online] = "0"
WHERE (([Product.Product Reference]= Like "*" & [ExcelOOS.Stk Code]));


and this (makes my machine hang)
CODE
UPDATE Product, ExcelOOS SET Product.[Can be ordered online] = "0"
WHERE (([Product.Product Reference]= "Like "*" & [ExcelOOS.Stk Code]"));

Plus others....

I'm sure this is school boy stuff, and I feel as i'm going bonkers, i'm sure the solution is staring me in the face!

This post has been edited by sir.chunk: 25 Jun, 2009 - 04:28 AM
User is offlineProfile CardPM
+Quote Post

sir.chunk

RE: Access Query

25 Jun, 2009 - 07:57 AM
Post #5

New D.I.C Head
*

Joined: 8 Dec, 2008
Posts: 7

Right this code using exact match returns 301 records to change
CODE
UPDATE Product, ExcelOOS SET Product.[Can be ordered online] = "0"
WHERE (([Product.Product Reference]=[ExcelOOS.Stk Code]));


And this one using the like command returns 3 records to change
CODE
UPDATE Product, ExcelOOS SET Product.[Can be ordered online] = "0"
WHERE (([Product.Product Reference] Like "*" & [ExcelOOS.Stk Code] & "*"));


Why is this, surely the like command code should return 301 plus more?!
My brain hurts, and i know it's gonna be simple

This post has been edited by sir.chunk: 25 Jun, 2009 - 07:58 AM
User is offlineProfile CardPM
+Quote Post

P4L

RE: Access Query

25 Jun, 2009 - 07:58 AM
Post #6

Geek 4 Life
Group Icon

Joined: 7 Feb, 2008
Posts: 2,163



Thanked: 16 times
Dream Kudos: 125
My Contributions
QUOTE(sir.chunk @ 25 Jun, 2009 - 04:12 AM) *

Right i have now linked a excel sheet to the access database, and have successfully run a query that changes a feild if another feild on the same row matches a field in the excel sheet.

CODE
UPDATE Product, ExcelOOS SET Product.[Can be ordered online] = "0"
WHERE (([Product.Product Reference]= [ExcelOOS.Stk Code]));


The problem i have now is that there are some fields that i want change if it contains the text i am trying to check e.g. 1!A567A to change if it contains A567A.
I am trying to use the like command with not much success. I've tried in all different ways i can think of but it's not happening sad.gif

I've tried this (syntax error)
CODE
UPDATE Product, ExcelOOS SET Product.[Can be ordered online] = "0"
WHERE (([Product.Product Reference]= Like "*" & [ExcelOOS.Stk Code]));


and this (makes my machine hang)
CODE
UPDATE Product, ExcelOOS SET Product.[Can be ordered online] = "0"
WHERE (([Product.Product Reference]= "Like "*" & [ExcelOOS.Stk Code]"));

Plus others....

I'm sure this is school boy stuff, and I feel as i'm going bonkers, i'm sure the solution is staring me in the face!



Try it this way:
SQL
UPDATE Product, ExcelOOS SET Product.[Can be ordered online] = "0"
WHERE (([Product.Product Reference] Like "*"
AND [Product.Product Reference]=[ExcelOOS.Stk Code]));


This post has been edited by P4L: 25 Jun, 2009 - 08:00 AM
User is offlineProfile CardPM
+Quote Post

P4L

RE: Access Query

25 Jun, 2009 - 08:05 AM
Post #7

Geek 4 Life
Group Icon

Joined: 7 Feb, 2008
Posts: 2,163



Thanked: 16 times
Dream Kudos: 125
My Contributions
QUOTE(sir.chunk @ 25 Jun, 2009 - 07:57 AM) *

Right this code using exact match returns 301 records to change
CODE
UPDATE Product, ExcelOOS SET Product.[Can be ordered online] = "0"
WHERE (([Product.Product Reference]=[ExcelOOS.Stk Code]));


And this one using the like command returns 3 records to change
CODE
UPDATE Product, ExcelOOS SET Product.[Can be ordered online] = "0"
WHERE (([Product.Product Reference] Like "*" & [ExcelOOS.Stk Code] & "*"));


Why is this, surely the like command code should return 301 plus more?!
My brain hurts, and i know it's gonna be simple



CODE
UPDATE Product, ExcelOOS SET Product.[Can be ordered online] = "0"
WHERE (([Product.Product Reference]=[ExcelOOS.Stk Code]));

This code is performing the same task as an INNER JOIN in Access, while the code below is saying to look at multiple criteria, and retrieve the rows that satisfy ALL the criteria.
CODE
UPDATE Product, ExcelOOS SET Product.[Can be ordered online] = "0"
WHERE (([Product.Product Reference] Like "*" & [ExcelOOS.Stk Code] & "*"));

User is offlineProfile CardPM
+Quote Post

sir.chunk

RE: Access Query

25 Jun, 2009 - 08:27 AM
Post #8

New D.I.C Head
*

Joined: 8 Dec, 2008
Posts: 7

QUOTE(P4L @ 25 Jun, 2009 - 07:58 AM) *

Try it this way:
SQL
UPDATE Product, ExcelOOS SET Product.[Can be ordered online] = "0"
WHERE (([Product.Product Reference] Like "*"
AND [Product.Product Reference]=[ExcelOOS.Stk Code]));



Thanks, this is further than i have got.
It gives the same results as using equals (301), but i know for a fact it should return at least 302+ records

This is what i want it to do:
First record in the excel sheet is A978D -- the code finds A978D in the product.product reference so it changes the 'product.Can be ordered online' field to '0'. The code also finds 1!A978D and changes the 'product.Can be ordered online' field. It also finds 2!A978D and does the same. Once it has gone through the 'product.product reference' column, it then goes onto the second record in the excel sheet.... and so on.

But it's not finding the 1!A978D, 2!A978D.... product codes.

This post has been edited by sir.chunk: 25 Jun, 2009 - 08:27 AM
User is offlineProfile CardPM
+Quote Post

P4L

RE: Access Query

25 Jun, 2009 - 11:54 AM
Post #9

Geek 4 Life
Group Icon

Joined: 7 Feb, 2008
Posts: 2,163



Thanked: 16 times
Dream Kudos: 125
My Contributions
QUOTE(sir.chunk @ 25 Jun, 2009 - 08:27 AM) *

QUOTE(P4L @ 25 Jun, 2009 - 07:58 AM) *

Try it this way:
SQL
UPDATE Product, ExcelOOS SET Product.[Can be ordered online] = "0"
WHERE (([Product.Product Reference] Like "*"
AND [Product.Product Reference]=[ExcelOOS.Stk Code]));



Thanks, this is further than i have got.
It gives the same results as using equals (301), but i know for a fact it should return at least 302+ records

This is what i want it to do:
First record in the excel sheet is A978D -- the code finds A978D in the product.product reference so it changes the 'product.Can be ordered online' field to '0'. The code also finds 1!A978D and changes the 'product.Can be ordered online' field. It also finds 2!A978D and does the same. Once it has gone through the 'product.product reference' column, it then goes onto the second record in the excel sheet.... and so on.

But it's not finding the 1!A978D, 2!A978D.... product codes.


Ok, run a simple query.

CODE

Select *
From Product,
ExcelOOS
Where [Product.Product Reference]=[ExcelOOS.Stk Code]


This will tell you how many row it is finding that are in common. This type of a query will bring back ALL the columns from BOTH tables where the product reference is the same as the ExcelOOS stk Code. If it brings back 302+ rows of data then there is a flaw in the UPDATE query.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/7/09 11:51PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month