Code issues.

Nothingness

New member
Local time
Today, 15:03
Joined
Feb 7, 2007
Messages
3
Hello,
I am having a problem with the following code. What I want to do is create a macro that when clicked it will store the data into a table. Everything works fine but when it goes to store the data a box pops up and asks you for the data you want entered, when it is already entered in the Forms.

Thank you in advanced.


The Code:
DoCmd.RunSQL "INSERT INTO [TemporaryData]([Period],[HMO],[EFB Data],[FOB Data],[EFB and FOB Data],[Total NonDDD],[Total DDD],[BN NonDDD],[BN DDD],[Payment Rate NonDDD],[Payment Rate DDD]) VALUES('#PeriodBox#','HMOBox',EFBBox,FOBBox,BlendedBox,TNDDDBox,TDDDBox,BNNDDBox,BNDDDBox,PRNDDDBox,PRDDDBox)"
 
You need to reference the form and the control.

Forms![FormName]![ControlName]
 
Actually, you need to break the control names out of the string so that their values are loaded into the string instead of their names. It should be written:
Code:
DoCmd.RunSQL "INSERT INTO [TemporaryData]([Period],[HMO],[EFB Data],[FOB Data],[EFB and FOB Data],[Total NonDDD],[Total DDD],[BN NonDDD],[BN DDD],[Payment Rate NonDDD],[Payment Rate DDD]) VALUES(#" & PeriodBox & "#,'" & HMOBox & "', " & EFBBox & ", " & FOBBox & ", " & BlendedBox & ", " & TNDDDBox & ", " & TDDDBox & ", " & BNNDDBox & ", " & BNDDDBox & ", " & PRNDDDBox & ", " & PRDDDBox & ")"

Assuming your VALUES are the names of controls on the form. Also note that I kept the # around PeriodBox because you had it in there originally, this is neccessary for Date type values. Also, I have ' ' around HMOBox because you had them in the original statement, these are neccesarry for string type values. So if any of those other fields contain dates or strings you will need to enclose them in # or ' respectively. Numerical data that is not stored as text in the table can be left without either.
 

Users who are viewing this thread

Back
Top Bottom