Insert Into problem

G

Guest

Hi there!

I'm trying to do the following. The form this code comes from is not bound
to any table and when I try to execute the code I get "Run Time Error 3075
Syntax Error in string in query expression '100000")'.

100000 is the number I have typed into the txtPrincipal text box. I
commented out a large block of the code to try a simpler example.

Private Sub cmdAdd_Click()
Dim MyDB As DAO.Database
'Dim rs As DAO.Recordset

Set MyDB = CurrentDb
' MyDB.Execute "Insert Into tblInt (Principal, Rate, Periods, IntEarned,
" _
' & "AmtEarned, Freq) Values (" _
' & [txtPrincipal] & ", " _
' & [txtInterestRate] & ", " _
' & [txtPeriods] & ", " _
' & [txtInterestEarned] & ", " _
' & [txtAmountEarned] & ", " _
' & [FraFrequency] & " "")"

MyDB.Execute "Insert Into tblInt (Principal) Values (" _
& [txtPrincipal] & " "") "

End Sub

Did I miss a comma or a quote somewhere or do I actually need to use a
recordset variable somewhere.

All help greatly appreciated!

John
 
G

GraemeR

Hi John, the quotes near the end of the string are malformed

MyDB.Execute "Insert Into tblInt (Principal) Values (" & [txtPrincipal] & ")
"

Or

MyDB.Execute "Insert Into tblInt (Principal, Rate, Periods, IntEarned, " _
& "AmtEarned, Freq) Values (" _
& [txtPrincipal] & ", " _
& [txtInterestRate] & ", " _
& [txtPeriods] & ", " _
& [txtInterestEarned] & ", " _
& [txtAmountEarned] & ", " _
& [FraFrequency] & ")"

HTH, Graeme.
 
G

Guest

Hi Graeme!

You rock! Thanks, that worked perfectly! Sometimes, I think I'm "malformed"!

John
 

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