473,406 Members | 2,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Dynamic lookup in SQL sentence

157 100+
Hello guys!

I have some trouble with my code

I have this sentence:

DoCmd.RunSQL "UPDATE [tbl productlines] SET ProductQuantity = 0 WHERE "ordernumber =" & me.ordernumber;"

which i use to update a subform from a mainform by button.

The ting is i need the ProductQuantity to lookup the value in a another table with a ProductNumber (which it finds at the subform it is trying to update) as identifier.

I have tried to use the Dlookup("ProductQuantity", "TBL ProductInformation", "Productnumber=" & me.productnumber) but it fails.

Please help me :)
May 11 '07 #1
12 2637
MrDeej
157 100+
When i use the DLookup("Product quantity", "tbl ProductInformation", "ProductNumber = " & [Form_orderline].Productnumber)
it uses the first ProductQuantity record from Productinformation on all records in [tbl Productline]

How can i make this dlookup use the productnumber in the SQL sentence and not in the subform?
May 11 '07 #2
MMcCarthy
14,534 Expert Mod 8TB
Your quotes are all wrong. Try this ...

Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunSQL "UPDATE [tbl productlines] SET ProductQuantity = 0 WHERE [ordernumber] =" & Me!ordernumber
Mary
May 12 '07 #3
MrDeej
157 100+
Your quotes are all wrong. Try this ...

Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunSQL "UPDATE [tbl productlines] SET ProductQuantity = 0 WHERE [ordernumber] =" & Me!ordernumber
Mary
Yes. But my problem is this:

ProductQuantity = 0 <---

I need a lookup which uses [tbl productlines].[product number] as criteria for [productquantity]
May 14 '07 #4
MMcCarthy
14,534 Expert Mod 8TB
Yes. But my problem is this:

ProductQuantity = 0 <---

I need a lookup which uses [tbl productlines].[product number] as criteria for [productquantity]
I don't understand. Can you explain in detail what you want your query to do?
May 14 '07 #5
MrDeej
157 100+
I don't understand. Can you explain in detail what you want your query to do?
I have 2 tabels.

[tbl product lines] and [tbl product information]

[tbl product lines] contains order information like which products and the quantity that belonds to a order number (product number, quantity, ordernumber, order quantity, etc etc]

[tbl product information] contains [product number], [product name], [product quantity] (in stock)

The subform is bound to [tbl product lines] and when i push a button on the main form i want all the [tbl product lines].[product quantity] fields in the subform to be updated with the value from [tbl product information].[product quantity]. The criteria is the [product number].

I am sorry about my bad explaining abilities. I am from Norway :)

Please ask me spesific if there are something you dont understand
May 14 '07 #6
Rabbit
12,516 Expert Mod 8TB
Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunSQL "UPDATE [tbl productlines] SET ProductQuantity = " & _ 
  2.    "DLookup(""Product quantity"", ""tbl ProductInformation""," & _
  3.    ""ProductNumber = "" & [Productnumber]) WHERE [ordernumber] =" & _
  4.    Me!ordernumber
I'm a little confused about exactly what you want but try this.
May 15 '07 #7
NeoPa
32,556 Expert Mod 16PB
Hello guys!

I have some trouble with my code

I have this sentence:

DoCmd.RunSQL "UPDATE [tbl productlines] SET ProductQuantity = 0 WHERE "ordernumber =" & me.ordernumber;"

which i use to update a subform from a mainform by button.

The ting is i need the ProductQuantity to lookup the value in a another table with a ProductNumber (which it finds at the subform it is trying to update) as identifier.

I have tried to use the Dlookup("ProductQuantity", "TBL ProductInformation", "Productnumber=" & me.productnumber) but it fails.

Please help me :)
May I ask why you're using DLookup at all.
You're already within SQL code. Why not link in the info you need using standard SQL?
May 15 '07 #8
MrDeej
157 100+
Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunSQL "UPDATE [tbl productlines] SET ProductQuantity = " & _ 
  2.    "DLookup(""Product quantity"", ""tbl ProductInformation""," & _
  3.    ""ProductNumber = "" & [Productnumber]) WHERE [ordernumber] =" & _
  4.    Me!ordernumber
I'm a little confused about exactly what you want but try this.
Thank you man!! At last it is working. :) :) :)
May 15 '07 #9
MrDeej
157 100+
May I ask why you're using DLookup at all.
You're already within SQL code. Why not link in the info you need using standard SQL?
Good question. I guess you should be able to use SQL code, but i am kindy a n00b at access so i dont know.

The only reference i have is a Wiley, John Walkenback Access 2003 bible as reference. And it is just not a complete bible.
May 15 '07 #10
NeoPa
32,556 Expert Mod 16PB
You seem happy enough with your answer, so that's good anyway :)
May 15 '07 #11
JConsulting
603 Expert 512MB
Hello guys!

I have some trouble with my code

I have this sentence:

DoCmd.RunSQL "UPDATE [tbl productlines] SET ProductQuantity = 0 WHERE "ordernumber =" & me.ordernumber;"

which i use to update a subform from a mainform by button.

The ting is i need the ProductQuantity to lookup the value in a another table with a ProductNumber (which it finds at the subform it is trying to update) as identifier.

I have tried to use the Dlookup("ProductQuantity", "TBL ProductInformation", "Productnumber=" & me.productnumber) but it fails.

Please help me :)
Glad you got this working, but it seems you could simply link your Main form and Subform using the Master/child relationship to achieve the same goal.
My .02
J
May 15 '07 #12
NeoPa
32,556 Expert Mod 16PB
My .02
J
Are you waiting for my "Do you need a '$' before your .02?"
To which your reply is on the lines of "Thanks. Very generous of you." :D
May 15 '07 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Greg Scharlemann | last post by:
I am attempting to populate a drop down menu based on the selection of a different drop down menu. However, it is not working correctly, I cannot figure out for the life of me what exactly happens...
0
by: Shailesh | last post by:
If I'm not mistaken, C++ doesn't have support for dynamic class members. I'm considering if such a facility would be useful, and what method would make a good workaround. I have a generic...
6
by: Jason | last post by:
I have two drop down lists on my asp.net page, the second of which needs to be filled in based on the selection in the first dropdownlist. The catch however, is that it must occur without a...
6
by: lloyduh234 | last post by:
Is there a way to dynamically create user scoped settings? For example, a lookup window inside an MDI application that is called by multiple forms and needs to maintain it's size and position based...
8
by: Sandy Pittendrigh | last post by:
I have a how-to-do-it manual like site, related to fishing. I want to add a new interactive question/comment feature to each instructional page on the site. I want (registered) users to be able...
11
by: Sean M. DonCarlos | last post by:
I have an unmanaged Win32 app that looks up the name of a DLL (unknown at compile time) from an external location, loads it with LoadLibrary, and then uses GetProcAddress on three exported...
7
by: | last post by:
I have what's probably a simple page lifecycle question related to dynamically evaluating values that are placed by a repeater and dynmically placing user controls that use those values. I'm...
3
by: SneakyElf | last post by:
Hi all, so i need to write a function called getString() that has a local char array of 80 elements. function should ask the user to enter a sentence, and store the sentence in the array. then...
3
by: Fraser Ross | last post by:
10.2/2 of the C++ standard says this: "The following steps define the result of name lookup in a class scope, C. First, every declaration for the name in the class and in each of its base class...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.