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?
The Field to be referenced in the PriceList Table is [ ID] and NOT [ ProductID] - Private Sub ProductID_AfterUpdate()
-
ProductName = DLookup("ProductName", "PriceList", "[ID] =" & ProductID)
-
Profit = DLookup("Profit", "PriceList", "[ID] =" & ProductID)
-
Price = DLookup("Price", "PriceList", "[ID] =" & ProductID)
-
Tax = DLookup("Tax", "PriceList", "[ID] =" & ProductID)
-
End Sub
13 2371
Kindly Post the code that you are using.
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?
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.
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.
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?
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: - Private Sub txtProductID_AfterUpdate()
-
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.
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.
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.
The Field to be referenced in the PriceList Table is [ ID] and NOT [ ProductID] - Private Sub ProductID_AfterUpdate()
-
ProductName = DLookup("ProductName", "PriceList", "[ID] =" & ProductID)
-
Profit = DLookup("Profit", "PriceList", "[ID] =" & ProductID)
-
Price = DLookup("Price", "PriceList", "[ID] =" & ProductID)
-
Tax = DLookup("Tax", "PriceList", "[ID] =" & ProductID)
-
End Sub
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.
That did it! I just knew I had to be missing something.
Sign in to post your reply or Sign up for a free account.
Similar topics
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
|
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...
|
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...
|
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...
|
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...
|
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:
...
|
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"...
|
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...
| |
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...
|
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,...
|
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$) {
}
...
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
| | |