Results 1 to 6 of 6

Thread: [RESOLVED] sql syntax error

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2005
    Location
    NTU, Singapore
    Posts
    42

    Resolved [RESOLVED] sql syntax error

    can someone please tell me what is wrong in syntax of this statement

    Dim strUser As String
    Dim dbs As DAO.Database
    Set dbs = CurrentDb
    Dim sql As String

    strUser = Environ("Username")
    sql = "INSERT INTO LogTable(Username,Date,Time,EditFields) VALUES('strUser',date,time,'New Mailbox created');"
    dbs.Execute sql


    It keeps giving a syntax error in "Insert Into" statement. Thanks

    Oh .. forgot to mention.. the LogTable has five fields (the first one is autogenerated number). Can it be the reason for the error?
    Last edited by rochak; Aug 10th, 2005 at 10:59 PM.

  2. #2
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: sql syntax error

    Try this...

    VB Code:
    1. SQL = "INSERT INTO LogTable(Username,[Date],[Time],EditFields) VALUES('strUser','" & Date & "','" & Time & "','New Mailbox created');"
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2005
    Location
    NTU, Singapore
    Posts
    42

    Re: sql syntax error

    Brilliant dee-u!! it's working. By the way, as I had expected in my logtable username field it is storing "strUser" instead of my actual strUser which is a variable. How do I modify my syntax for the strUser variable?

    Also, if you have time can you please explain why you put [Date] and [Time] in square brackets.. Thanks a lot

  4. #4
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: sql syntax error

    It is because Date and Time are Visual Basic functions.

    VB Code:
    1. SQL = "INSERT INTO LogTable(Username,[Date],[Time],EditFields) VALUES('" & strUser & "','" & Date & "','" & Time & "','New Mailbox created')
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  5. #5

    Thread Starter
    Member
    Join Date
    Aug 2005
    Location
    NTU, Singapore
    Posts
    42

    Re: sql syntax error

    Thank you. All problem solved.

  6. #6
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: sql syntax error

    You could mark this thread as resolved now. Take a look at my sig on how to do it.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

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