Update a table using CreateQueryDef

  • Thread starter Kpakute via AccessMonster.com
  • Start date
K

Kpakute via AccessMonster.com

I have a "Sold" table with the following fields. StoredID, ProductID,
Quantity. StoredID and ProductID are composite key.

I want a situation where I click a button on my form, it increases the
Quantity value by 1 for the displayed first columns of StoredID combobox
and ProductID combobox.

These combo boxes a multi-columned but are bound to the different tables.

This is the On_Click event code.

Dim D As Database
Dim Q As QueryDef
Dim strSQL As String

Set D = CurrentDb()
strSQL = "UPDATE Sold "
strSQL = strSQL & "SET Sold.Quantity = [Quantity]+1 "
strSQL = strSQL & "WHERE (((Sold.ProductID)=" & Me![ProductID] & ") AND
((Sold.BedID)=" & Me![StoreID] & "));"

MsgBox strSQL

Set Q = D.CreateQueryDef("", strSQL)

Q.Execute dbFailOnError

Anytime I run this code I keep getting,
"run-time error '3061': Too few parameters. Expected 2".

I have run the query using QBE and it does the increment. Can anyone tell
me what I'm doing wrong and help fix my problem?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top