Results 1 to 4 of 4
  1. #1
    hugo68 is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2014
    Posts
    2

    Sql insert button

    Hi, need help braking in to muliple line an sql insert stetement, so basicly what im trying to do is to duplicate the record that im currently working on form so when i click on button it saves the updated record plus a copy of it self as a new record on the respective table; I have the sql code, it works but i cant get the code to go to a new line as i have about 100 fileds on table. Here is what i got



    CurrentDb.Execute "Insert Into [Contacts]([FULL NAME], [WORK ORDER], [STATUS], [ADDRESS], [CITY], [ST], [ZIP], [HOME], [CELL], [EMAIL], [FACEBOOK], [INSTAGRAM], [TWITTER], [CINTURA], [CADERA], [ALTO DE CADERA], [LARGO DE FALDA], [TALLE DELANTERO], [TALLE TRACERO], [AXILA FRENTE], [AXILA ESPALDA], [ALTO DE AXILA], [CONTORNO BUSTO], [CONTORNO DE TORAX], [ALTO DE BUSTO], [SEPARACION DE BUSTO], [CONTORNO BAJO BUSTO], [ALTO DE BAJO BUSTO], [HOMBRO], [LARGO DE MANGA], [BRASO], [PUņO], [MUņECA], [ESCOTE], [LARGO DE PANTALON], [LARGO DE RRODILLA], [LARGO DE TIRO]) Values) Values('" & Me![Full Name] & "', '" & Me![Work Order] & "', '" & Me![Status] & "', '" & Me![Address] & "', '" & Me![City] & "', '" & Me![St] & "', '" & Me![Zip] & "', '" & Me![Home] & "', '" & Me![Cell] & "', '" & Me![Email] & "', '" & Me![Facebook] & "', '" & Me![Instagram] & "', '" & Me![Twitter] & "' , '" & Me![Cintura] & "', '" & Me![Cadera] & "', '" & Me![Alto de cadera] & "', '" & Me![Largo de falda] & "', '" & Me![Talle delantero] & "', '" & Me![Talle tracero] & "', '" & Me![Axila frente] & "', '" & Me![Axila espalda] & "', '" & Me![Alto de axila] & "', '" & Me![Contorno busto] & "', '" & Me![Contorno de torax] & "', '" & Me![Alto de busto] & "', '" & Me![Separacion de busto] & "', '" & Me![Contorno bajo busto] & "', '" & Me![Alto de busto] & "', '" & Me![Hombro] & "', '" & Me![Largo de manga] & "', '" & Me![Braso] & "', '" & Me![Puņo] & "', '" & Me![Muņeca] & "', '" & Me![Escote] & "', '" & Me![Largo de pantalon] & "', '" & Me![Largo de rrodilla] & "', '" & Me![Largo De Tiro] & "')"
    So all of this code needs to be broken in to different lines as it is too long to fit in one, any help will be appreciated.
    Thaks

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    Dont use "CurrentDb.Execute"
    Use an append query ..and run docmd.openquery "qaAddDupeRec"

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    [LARGO DE TIRO]) Values) Values('" & Me![Full Name]
    You have extra "Values)" in the SQL.


    i have about 100 fileds on table
    You might want to reevaluate the table. 100 fields seems a little excessive.
    In the table "Contacts", why is there a field "ALTO DE CADERA"? I would think the field should be in a different table related to the contacts.
    Also, it would be better if you didn't have spaces in object names. Maybe something like "Alto_De_Cadera" or "AltoDeCadera", rather than "ALTO DE CADERA"

    Is the form a bound form with bound controls?
    If yes, you need to save the original data BEFORE editing any fields. Or you need to write a lot of VBA to check each field to see if the data has changed. (compare the value to the old value properties).

    An "INSERT INTO" SQL statement inserts (adds) a new record to a table.... it doesn't go to a "New" record and add the data.


    Hi, need help braking in to muliple line an sql insert stetement,
    It would look like this to break up the SQL statement:
    Code:
    Dim sSQL as string
    
    sSQL = "Insert Into [Contacts]([FULL NAME], [WORK ORDER], [STATUS],"
    sSQL = sSQL & " [ADDRESS], [CITY], [ST], [ZIP], [HOME], [CELL], [EMAIL],"
    sSQL = sSQL & " [FACEBOOK], [INSTAGRAM], [TWITTER], [CINTURA], [CADERA],"
    sSQL = sSQL & " [ALTO DE CADERA], [LARGO DE FALDA], [TALLE DELANTERO],"
    sSQL = sSQL & " [TALLE TRACERO], [AXILA FRENTE], [AXILA ESPALDA], [ALTO DE AXILA],"
    sSQL = sSQL & " [CONTORNO BUSTO], [CONTORNO DE TORAX], [ALTO DE BUSTO],"
    sSQL = sSQL & " [SEPARACION DE BUSTO], [CONTORNO BAJO BUSTO], [ALTO DE BAJO BUSTO],"
    .
    .
    .
    sSQL = sSQL & " Values('" & Me![Full Name] & "', '" & Me![Work Order] & "', '" 
    sSQL = sSQL &  Me![Status]"', '" & Me![Address] & "', '" & Me![City] & "', '" & Me![St] & "', '" 
    sSQL = sSQL &  Me![Zip] & "', '" & Me![Home] & "', '" & Me![Cell] & "', '" & Me![Email] & "', '"
    sSQL = sSQL &  Me![Facebook] & "', '" & Me![Instagram] & "', '" & Me![Twitter] & "' , '"
    .
    .
    .
    
    ' Debug.Print sSQL '<= to check the SQL statement
    
    CurrentDb.Execute sSQL, dbfailonerror
    I didn't do all of the lines....... but you get the idea.....

  4. #4
    hugo68 is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2014
    Posts
    2
    Thanks for the reply, i was out of town for a wile, it findly worked with your help. Thank you again.

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

Similar Threads

  1. Creating an "Insert Record" Button
    By ZachAtaiyan in forum Forms
    Replies: 4
    Last Post: 08-08-2014, 11:22 AM
  2. Replies: 4
    Last Post: 05-17-2013, 04:00 PM
  3. Replies: 5
    Last Post: 03-04-2012, 01:21 PM
  4. Insert multiple records button
    By Aragan in forum Forms
    Replies: 6
    Last Post: 01-03-2012, 10:57 AM
  5. Replies: 5
    Last Post: 01-14-2010, 03:37 PM

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