Results 1 to 4 of 4
  1. #1
    pritesharyan is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2015
    Location
    India
    Posts
    32

    Insert into table, Only if i change table name, Why?

    here is my project
    now i try to insert data into Order table using click event
    of button on Main form in my project.
    in my project i have order form and order table.


    i can only insert data if i change my table name to
    order1.
    i don't want to change talbe name
    any solution??
    Below is my Click event code.
    Code:
    Private Sub Command127_Click()
        
        Dim StrSQL As String
        Dim InDate As String
         
         
        InDate = Format(Date, "dd-MM-yyyy")
       
         'this doesn't work because i think may be form name and table name are same
         'what shoul i have to do?? i don't want to change table name.
         StrSQL = " INSERT INTO Order1([CustomerID],[EmployeeID],[OrderDate],[RequiredDate],[FinishedDate],[Tax],[OtherAmount],[Diary],[Note],[LastEditDate]) VALUES (1,1,#" & InDate & "#,#" & InDate & "#,#" & InDate & "#,10,450,'Diary','Note',#" & InDate & "#)"
      
        'It works if i change table name to Order1
         'StrSQL = " INSERT INTO Order1([CustomerID],[EmployeeID],[OrderDate],[RequiredDate],[FinishedDate],[Tax],[OtherAmount],[Diary],[Note],[LastEditDate]) VALUES (1,1,#" & InDate & "#,#" & InDate & "#,#" & InDate & "#,10,450,'Diary','Note',#" & InDate & "#)"
        
        DoCmd.SetWarnings False
        DoCmd.RunSQL StrSQL
        DoCmd.SetWarnings True
        
    End Sub

  2. #2
    pritesharyan is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2015
    Location
    India
    Posts
    32
    I have just googling and found that just write table name in squre bracket and it works. see below query
    StrSQL = " INSERT INTO [Order]([CustomerID],[EmployeeID],[OrderDate],[RequiredDate],[FinishedDate],[Tax],[OtherAmount],[Diary],[Note],[LastEditDate]) VALUES (1,1,#" & InDate & "#,#" & InDate & "#,#" & InDate & "#,10,450,'Diary','Note',#" & InDate & "#)"
    Sorry for disturbing all friends with stupid question.

  3. #3
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,446
    the reason you are having a problem is that 'order' is a reserved word - for example it is used in SQL in ORDER BY.

    putting it into square brackets will often solve the problem but will not always do so. It is strongly recommended you change the name to something else

    here is a list of reserved words

    https://support.office.com/en-za/art...7-da237c63eabe

  4. #4
    pritesharyan is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2015
    Location
    India
    Posts
    32
    Oh i see.
    Thank you so much for replying its vital information for me.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 06-12-2015, 02:02 PM
  2. Replies: 5
    Last Post: 12-01-2014, 11:31 AM
  3. Replies: 2
    Last Post: 12-20-2011, 07:33 AM
  4. Replies: 2
    Last Post: 12-22-2010, 01:46 PM
  5. Replies: 0
    Last Post: 02-24-2010, 12:56 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums