Unfortunately it will take forever to go back and change all of the fields
and control name and references and whatnot to names without space. Either
way I redid the sql statements to what you posted above and it seemed to be
working, but for whatever reason, it is not now... It keeps giving me
"didn't add 1 record to the table due to key violations". Now I am adding
this to an empty table. The primary key is an autonumber field. I don't see
how there can be duplicate key entries like that. Any thoughts?
SQLText = "INSERT INTO Charges ([Service Name], [Charge Amount], [Account
Number])"
SQLText = SQLText & " Values( """ & Me![Service Name] & """, """ &
Me![Charge Amount] & """, """ & Me![Account Number] & """)"
DoCmd.RunSQL SQLText
SQLText2 = "INSERT INTO Payments ([Payment Amount], [Account Number],
[Notes])"
SQLText2 = SQLText2 & " Values(""" & Me![Payment Amount] & """, """ &
Me![Account Number] & """, """ & Me![Notes] & """)"
DoCmd.RunSQL SQLText2
Cory
John Spencer said:
Try the alternate syntax.
AND all your field names and control names have S P A C E S which means you will
have to use [] around them. You are much better off codewise if you eliminate
those spaces.
In addition, if your field is a text (string) field, you will need to have quote
marks around the values you are going to insert. I assummed that Service Name
and Account Number are text fields and not number field and Charge Amount is a
number field.
SQLTExt = "INSERT INTO Charges ([Service Name], [Charge Amount], [Account Number])"
SQLText = SQLText & " Values( """ & Me![Service Name] & """, " & Me![Charge
Amount] &
", """ & Me![Account Number] & """)"
Cory wrote:
I have added the following code to the onClick event on a button on an Add
Account form. I want it to add a record to the Charges table using the
values that are in several controls on that form. I can't for the life of me
figure out what I am doing wrong. Any help would be greatly appreciated.
Dim SQLText As String
SQLText = "INSERT INTO Charges (Service Name, Charge Amount, Account Number)"
SQLText = SQLText & " SELECT " & Me!Service Name & ", " & Me!Charge Amount &
", " & Me!Account Number & ""
DoCmd.RunSQL SQLText
Cory