473,385 Members | 2,210 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,385 software developers and data experts.

DLOOKUP works in test database, but not in real one

Seth Schrock
2,965 Expert 2GB
I ran a test database that looks up product information from the Products table to populate fields in the Sales table through a form. In the test DB, I enter the product number, and the item description and price appear(I used DLOOKUP to do this). When I manually copy the code over to the real DB, it doesn't matter what product ID I type in, only the first item in the Products table populates the Item description and Price fields. On both databases, I used VBA under the After Update event. I have opened both VBA files and they look exactly the same. Why does one work and the other doesn't? Is there a better way to do the same thing besides DLOOKUP?
Dec 30 '10 #1

✓ answered by ADezii

The Field to be referenced in the PriceList Table is [ID] and NOT [ProductID]
Expand|Select|Wrap|Line Numbers
  1. Private Sub ProductID_AfterUpdate()
  2.   ProductName = DLookup("ProductName", "PriceList", "[ID] =" & ProductID)
  3.   Profit = DLookup("Profit", "PriceList", "[ID] =" & ProductID)
  4.   Price = DLookup("Price", "PriceList", "[ID] =" & ProductID)
  5.   Tax = DLookup("Tax", "PriceList", "[ID] =" & ProductID)
  6. End Sub

13 2371
ADezii
8,834 Expert 8TB
Kindly Post the code that you are using.
Dec 30 '10 #2
Seth Schrock
2,965 Expert 2GB
Private Sub ProductID_AfterUpdate()
ProductName = DLookup("ProductName", "PriceList", "[ProductID] =" & ProductID)
Profit = DLookup("Profit", "PriceList", "[ProductID] =" & ProductID)
Price = DLookup("Price", "PriceList", "[ProductID] =" & ProductID)
Tax = DLookup("Tax", "PriceList", "[ProductID] =" & ProductID)
End Sub

All fields in the form are text boxes. It doesn't matter what product ID I put in the ProductID text-box, the same product name, profit, price and tax shows up. I also just remembered, the one where it works has the ProductID as a combo box that is linked to both the ProductID and ProductName, but it just shows the ProductName. Is that the difference, combo-box vs. text-box?
Dec 30 '10 #3
ADezii
8,834 Expert 8TB
Personally, I would include all 5 Fields in the Row Source of the Combo Box, hide selective Fields, then derive the appropriate Values once the User has selected a Product based on the Column Number. I created a Demo that includes all the Fields, displays only the [ProductName] Field (sorted alphabetically), while hiding the other Fields (Columns). Once a Value is selected, the other Fields are pushed to the appropriate Text Boxes. This approach is essentially foolproof, since there can be no Typos, and the only Values that may be selected are those in PriceList Table (LimitToList = Yes). Download the Attachment to see what I am referring to.
Attached Files
File Type: zip DLookup.zip (21.2 KB, 167 views)
Dec 30 '10 #4
Seth Schrock
2,965 Expert 2GB
I really don't want to use a combo box. For my store, a item number works better because of having different shipments of the same item costing different amounts. A text box which allows you to enter a item number that is placed on the product is easier than looking through product, new product, 3rd shipment product, etc. At first I liked the idea, but after thinking about it for a while, a combo box just won't work for me. Using your DB as an example, I would leave off the combo box, type the product ID in, and have the rest of the fields fill. Does that make sense? The reason that I started with a combo box was that it was the way described in a video I found online. It was when I tried translating that into a text-box as the source that I ran into trouble.
Dec 31 '10 #5
ADezii
8,834 Expert 8TB
In that case:
Attached Files
File Type: zip DLookup_2.zip (17.4 KB, 110 views)
Dec 31 '10 #6
Seth Schrock
2,965 Expert 2GB
That looks like it will work! Now I have to figure out how you did it :) I assume that the Private Sub cboProducts_AfterUpdate section is no longer being used. What is the DCount command being used for? Why do you use the Me![txtProductName]=DLookup... and all of the others instead of just ProductName=DLookup...? I really want to know because I would like to understand the VBA side of Access much more. Do you have any recommendations for books that I should study or websites so that I could learn this stuff? I was looking at Access 2007 VBA Programmer's Reference on Amazon. What do you think of it?
Jan 1 '11 #7
ADezii
8,834 Expert 8TB
1) I assume that the Private Sub cboProducts_AfterUpdate section is no longer being used
That is correct and is replaced by the AfterUpdate() Event of txtProductID, namely:
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtProductID_AfterUpdate()
  2. End sub
2) What is the DCount command being used for?
It lets you find out whether or not there are any Records that match the ProductID.
3) Why do you use the Me![txtProductName]=DLookup... and all of the others instead of just ProductName=DLookup...?
You could very well assign the Result of the DLookup() Functions to Variables, but I chose to simply write the Results to Text Boxes on the Form.
Jan 1 '11 #8
Seth Schrock
2,965 Expert 2GB
For the third question, I wasn't meaning variables, but the names of the text-box controls. Here is what I had before that didn't work. It kind of gives you an idea of the format that I'm looking for. Hopefully I will be able to do a bit of copy and paste with a very few changes to get it to work.
Attached Files
File Type: zip Temp Store Database.zip (111.0 KB, 115 views)
Jan 1 '11 #9
ADezii
8,834 Expert 8TB
Sorry, but I am using Access 2003, but if you can Convert it to 2003 Format, I'll be more than happy to have alook at it.
Jan 1 '11 #10
Seth Schrock
2,965 Expert 2GB
Sorry, here it is.
Attached Files
File Type: zip Temp Store Database.zip (60.9 KB, 102 views)
Jan 1 '11 #11
ADezii
8,834 Expert 8TB
The Field to be referenced in the PriceList Table is [ID] and NOT [ProductID]
Expand|Select|Wrap|Line Numbers
  1. Private Sub ProductID_AfterUpdate()
  2.   ProductName = DLookup("ProductName", "PriceList", "[ID] =" & ProductID)
  3.   Profit = DLookup("Profit", "PriceList", "[ID] =" & ProductID)
  4.   Price = DLookup("Price", "PriceList", "[ID] =" & ProductID)
  5.   Tax = DLookup("Tax", "PriceList", "[ID] =" & ProductID)
  6. End Sub
Jan 1 '11 #12
Seth Schrock
2,965 Expert 2GB
I will have to change that and see if it works. I figured it was some simple problem like that, but I looked and looked and still missed it. As soon as I get a chance I will try that and see if it fixes the problem. Thank you so much for your help. I will also try your code and see if I can duplicate what you did. Thanks again.
Jan 3 '11 #13
Seth Schrock
2,965 Expert 2GB
That did it! I just knew I had to be missing something.
Jan 5 '11 #14

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

Similar topics

1
by: Spyros | last post by:
Yes, I deleted the mysql and th test database from a mysql server on a Linux system. What next? Please help Spyros
1
by: Justin Allen | last post by:
I am using SQL 2000, 2000 Server. I need to find out how to schedule a database export import. I have a production database that I need to easily copy to a test database occassionaly. When I run...
2
by: Justin Allen | last post by:
SQL 2000, Windows 2000. I need to find a way to export our data from our production database and import it into a test database. I can do it to a freshly created test database I just have trouble...
1
by: Sanjay Asrani | last post by:
A test database that we used in one of our implementation pilots was abandoned around 4 months back. The database when abandoned had a log file size of less than 500MB. The log file has been...
1
by: Microlong® | last post by:
I have a problem in the ASP Page. I use the ASP page to test whether the connection of SQL Server is fine. I use windows authentication. I get fail when I attempt to use hostname of the destination...
24
by: Henrik Steffen | last post by:
hello all, on my master-db-server i'm running postgres 7.4.1, and I have got two slave-servers running postgres 7.4.2 running the following query on the master-server (7.4.1) delivers: ...
2
by: Michel Esber | last post by:
Hello, DB2 V7 FP14 running Linux. Our application constantly tests whether the database connection is still alive before sending new statements to the DB. A "values current timestamp"...
0
by: alvinstraight38 | last post by:
Hey guys, I have a client that is using a SQL database driven software. SQL and the databases are housed on a separate server, and the software is installed on the workstation. We use a...
2
by: Praveenkumarawasthi | last post by:
I want to test test database Trigers
4
by: Neil | last post by:
I need to create a test database on the live server for performance testing. From time to time, as structural modifications are made to the live database, I'd like to be able to delete the test...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.