By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,203 Members | 1,383 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,203 IT Pros & Developers. It's quick & easy.

Autofill information from a table

P: 1
I am having a hard time with my database (Access 2003) and I hope someone can help. What I doing is creating an order form, and what I would like to have happen is when a product ID is entered, the relating information to that product will self populate. I did some looking around online and in various books and was able to come up with a script. I manipulated it and tried it and it is close but not quite. Instead of populating the information that goes along with the specific product number, it just brings up the information relating to the first product in the product table.
(the product name, cost and weight comes up for the first product in my product table regardless of what product number i type in)

This is the code that I found and I have placed it in the "after update" field of the "ProdID" field in my form.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub ProdID_AfterUpdate()
  3. Dim varProdName, varProdCost, varWeight As Variant
  4.     varProdName = DLookup("ProdName", "Products", "ProdID =[ProdID] ")
  5.     varProdCost = DLookup("ProdCost", "Products", "ProdID =[ProdID] ")
  6.     varWeight = DLookup("weight", "Products", "ProdID =[ProdID] ")
  7.  
  8.     If (Not IsNull(varProdName)) Then Me![ProdName] = varProdName
  9.     If (Not IsNull(varProdCost)) Then Me![ProdCost] = varProdCost
  10.     If (Not IsNull(varWeight)) Then Me![Weight] = varWeight
Feb 27 '07 #1
Share this Question
Share on Google+
1 Reply


MMcCarthy
Expert Mod 10K+
P: 14,534
Change code to ...

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub ProdID_AfterUpdate()
  3. Dim varProdName, varProdCost, varWeight As Variant
  4.  
  5.     varProdName = DLookup("ProdName", "Products", "ProdID=" & Me.ProdID)
  6.     varProdCost = DLookup("ProdCost", "Products", "ProdID=" & Me.ProdID)
  7.     varWeight = DLookup("weight", "Products", "ProdID=" & Me.ProdID)
  8.  
  9.     If (Not IsNull(varProdName)) Then Me![ProdName] = varProdName
  10.     If (Not IsNull(varProdCost)) Then Me![ProdCost] = varProdCost
  11.     If (Not IsNull(varWeight)) Then Me![Weight] = varWeight
  12.  
Feb 27 '07 #2

Post your reply

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