Help with SQL Statement

I need help with an Update SQL for a form, which also contains a subform. Once a record is saved in tblContacts, I would like to create a corresponding record in tblHeuristics that has the Contact ID saved as the as the foreign key as well as the value of a control named "cboAskAmount" whose record source is [SuggestedAskAmount] the code I have written below doesn't work, which doesn't surprise me since I am new to VBA. Can anyone help?
INSERT INTO tblheuristics ( fk_ContactID, SuggestedAskAmount )
SELECT tblHeuristics.fk_ContactID, tblHeuristics.SuggestedAskAmount
FROM tblHeuristics
WHERE (((tblHeuristics.SuggestedAskAmount)=[Me].[subfrmHeuristics].[Form].[cboAskAmount].[Value]));

Open in new window

Harry BattDirector of DevelopmentAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Russell FoxDatabase DeveloperCommented:
In VBA you can't just run SQL code like that - you'll need to create a string with your SQL command and run it with DoCmd.RunSQL:
Dim SQL As String 
     
SQL = "INSERT INTO tblheuristics ( fk_ContactID, SuggestedAskAmount ) " & _ 
	"SELECT tblHeuristics.fk_ContactID, tblHeuristics.SuggestedAskAmount " & _ 
	"FROM tblHeuristics " & _ 
	"WHERE (((tblHeuristics.SuggestedAskAmount)=" & [Me].[subfrmHeuristics].[Form].[cboAskAmount].[Value] & "));"

DoCmd.RunSQL SQL 

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
als315Commented:
Use query builder in Access, it can save you a lot of time. You can't use Me in queries, only in VBA, but you can use full syntax:
Forms![YourMainForm]![subfrmHeuristics].Form![cboAskAmount]
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.