Results 1 to 5 of 5

Thread: insert statement-Syntax error

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2009
    Location
    Singapore
    Posts
    355

    insert statement-Syntax error

    I don't which part when wrong, i had been googling for hours and now() is suppose to give us a timestamp but when i print out the sql i got this syntax error.

    can someone advice me which syntax error in my insert statement is occuring?

    Code:
    sql = "Insert into Followup(Followup, FollowUpDate, Check, CompanyName, Category, Timestamp) Values ('" & Me.txt_f1 & "', '" & Me.txt_fdate1 & "', '" & Me.chk_r1 & "', '" & Me.lb_companyName & "','" & Me.lb_category & "', NOW())"
    MsgBox sql
    Here is what is shows in the print out msgbox.
    Name:  syntax.png
Views: 139
Size:  24.3 KB

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: insert statement-Syntax error

    try
    Code:
    sql = "Insert into Followup(Followup, FollowUpDate, Check, CompanyName, Category, Timestamp) Values ('" & Me.txt_f1 & "', '" & Me.txt_fdate1 & "', '" & Me.chk_r1 & "', '" & Me.lb_companyName & "','" & Me.lb_category & "'," &  NOW() & ")"
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,531

    Re: insert statement-Syntax error

    Still not quite right... need enclosing ticks around the timestamp value.

    Even still... parameters would be a better way to go. Also I think (think, not sure) that TmeStamp might be a reserved word ... it's a type in SQL Server.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: insert statement-Syntax error

    need enclosing ticks around the timestamp value
    also if timestamp is a date field, probably should be hashes instead
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2009
    Location
    Singapore
    Posts
    355

    Re: insert statement-Syntax error

    This code works for the timestamp. Thanks.
    Quote Originally Posted by westconn1 View Post
    try
    Code:
    sql = "Insert into Followup(Followup, FollowUpDate, Check, CompanyName, Category, Timestamp) Values ('" & Me.txt_f1 & "', '" & Me.txt_fdate1 & "', '" & Me.chk_r1 & "', '" & Me.lb_companyName & "','" & Me.lb_category & "'," &  NOW() & ")"
    but the timestamp still remain unresolve. As i did try to change the word timestamp to TS, the error still occurred.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width