error on inserting value to the table

dada123

Registered User.
Local time
Today, 06:04
Joined
Aug 16, 2010
Messages
10
anyone can tell me what's wrong with this code? it keeps on giving me error "Number of query values and destination fields are not the same".. please help..

btw, cTime and ccDate are Textbox

Dim sql, in_sql, out_sql As String
sql = "INSERT INTO Transaction(TimeIn , EntryDate) VALUES ('"
sql = sql & cTime & "," & ccDate & "')"
DoCmd.RunSQL (sql)
 
Rather than surrounding each value with the single quote delimiter, you've got one before the first value and one after the last. Also the date/time delimiter is # rather than '.
 
thanks for the reply and info! :D
 
In addition...
1) date and time are more commonly stored in one field, not 2 seperate ones.
2) Dim sql, in_sql, out_sql As String
doesnt work the way you expect/hope it to, this should read:
Dim sql As String, in_sql As String, out_sql As String
3) Dont randomly cut up your sql, keep it readable, keep it maintable:
Code:
sql = ""
sql = sql & "INSERT INTO Transaction(TimeIn , EntryDate) "
sql = sql & " VALUES ('" & cTime 
sql = sql & "         ," & ccDate & "')"
4)
Docmd.runsql, this will popup an ugly non-user-friendly message.
Perhaps you want to use: Currentdb.Execute SQL
instead or use Docmd.Setwarnings
to eliminate the message
5) I believe sql to be a reserved word, which can potentially lead to problems.
In any case it is smart to adhere a naming convention:
mySQL
strSQL
or something simular

Good luck with your project :)
 

Users who are viewing this thread

Back
Top Bottom