Connecting Tech Pros Worldwide Forums | Help | Site Map

Autofill information from a table

Newbie
 
Join Date: Feb 2007
Posts: 1
#1: Feb 27 '07
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
msquared's Avatar
Administrator
 
Join Date: Aug 2006
Location: Dublin, Ireland
Posts: 10,866
#2: Feb 27 '07

re: Autofill information from a table


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.  
Reply