Posted by: nepalikanchha September 15, 2006
MS Access Question - technical
Login in to Rate this Post:     0       ?        
I'm pretty positive that Access SQL is pretty limited and will not allow you to use If-Then or other programming languages. The only way I can think of accomplishing what you want is as follows: Setup two tables: Fruits & FruitsDistribution I have attached "Fruits" table with this post. Setup "FruitsDistribution" the same way as "Fruits" but leave it empty. Create a form and add a button called "cmdCalculate". Copy the following code to cmdCalculate: Set db = CurrentDb strQry = "SELECT * FROM Fruits" Set rec = db.OpenRecordset(strQry, dbOpenDynaset) rec.MoveFirst Do Until rec.EOF If rec.Fields(0) = "Apple" Then strInsert = "INSERT INTO FruitsDistribution VALUES ('" & rec.Fields(0) & "', " & rec.Fields(1) * 2 & ")" db.Execute (strInsert) End If If rec.Fields(0) = "Oranges" Then strInsert = "INSERT INTO FruitsDistribution VALUES ('" & rec.Fields(0) & "', " & rec.Fields(1) * 4 & ")" db.Execute (strInsert) End If If rec.Fields(0) = "Mangoes" Then strInsert = "INSERT INTO FruitsDistribution VALUES ('" & rec.Fields(0) & "', " & rec.Fields(1) * 3 & ")" db.Execute (strInsert) End If If rec.Fields(0) = "Grapes" Then strInsert = "INSERT INTO FruitsDistribution VALUES ('" & rec.Fields(0) & "', " & rec.Fields(1) / 10 & ")" db.Execute (strInsert) End If rec.MoveNext Loop There might be easier way, but, I'm just out of ideas right now.
Read Full Discussion Thread for this article