Results 1 to 7 of 7
  1. #1
    Aragan is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jan 2012
    Posts
    22

    Insert multiple records button


    Hi, im new using access 2007 and i have a problem, i would like to create a button that save a new record "x" times (INSERT INTO blablabla), where "x" is a number contained in a field of the form, how can i do this? thanks in advance!

  2. #2
    Aragan is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jan 2012
    Posts
    22
    im trying something like this but isnot working... whats the problem?

    Private Sub Guardar_Click()
    Dim num20 As Integer

    num20 = Me.Testo33.Value

    For counter = 0 To num20
    DoCmd.RunSQL "INSERT INTO Contratos(Nombre Agente) VALUES('test');"
    Next
    End Sub

  3. #3
    Aragan is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jan 2012
    Posts
    22
    Well...ive been searching all day!! i finally found the answer in other forums... i will post it in case that helps somebody else...

    The exact error message was:
    Microsoft Office Access can't append all the records in the append query.

    Microsoft Office Access set 0 field(s) to Null due to a type conversion failure, and it didn't add 1 record(s) to the table due to key violations, 0 record(s) due to lock violations, and 0 record(s) due to validation rule violations.
    Do you want to run the action query anyway?
    To ignore the error(s) and run the query, click Yes.
    For an explanation of the causes of the violations, click Help.
    The problem was that i cannot insert a "test" value to [Nombre Agente] because is a foreign key with the referential integrity, so.. as the "test" value was not in the othe table i got the error msg! anyways thanks!

  4. #4
    Aragan is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jan 2012
    Posts
    22
    Now i have another problem... the code works but it adds one extra row to the table dont know why...

    Code:
    Private Sub Guardar_Click()
    Dim num20 As Integer
    
    num20 = Me.Testo33
    For i = 1 To num20
    DoCmd.SetWarnings False
    DoCmd.RunSQL "INSERT INTO Contratos ([Nombre Agente],[Nombre Cliente],DNI,[Nombre Empresa],CIF,[Telefono Fijo 1], [Telefono Fijo 2], [Telefono Movil], Tarifa, [Fecha WE Entrega], [Fecha WE Pago], [Fecha Daily]) VALUES ('" & Me.Nombre_Agente & "','" & Me.Nombre_Cliente & "','" & Me.DNI & "','" & Me.Nombre_Empresa & "','" & Me.CIF & "','" & Me.Telefono_Fijo_1 & "','" & Me.Telefono_Fijo_2 & "','" & Me.Telefono_Movil & "','2.0','" & Me.Fecha_WE_Entrega & "','" & Me.Fecha_WE_Pago & "','" & Me.Fecha_Daily & "')"
    DoCmd.SetWarnings True
    Next i
    Me.Requery
    End Sub
    For example if if num20 is "4" the code inserts 5 rows.. but in the 1st one the field "Tarifa" is empty. Tarifa is the only field that im passing a string instead of a parameter from the form... could someone explain me why? thx

    http://imageshack.us/photo/my-images/827/clipboard02oy.jpg/

  5. #5
    Aragan is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jan 2012
    Posts
    22
    If num20 is 0 or negative the code still inserting 1 row with "Tarifa" field empty... come on... anybody???? >_<

  6. #6
    Aragan is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jan 2012
    Posts
    22
    If i remove everything! except the insert into it stills inserting 2 rows, and one with "tarifa" empty, whyyyyyyyy? :s like

    Code:
    Private Sub Guardar_Click()
     DoCmd.RunSQL "INSERT  INTO Contratos ([Nombre Agente],[Nombre   Cliente],DNI,[Nombre  Empresa],CIF,[Telefono Fijo 1], [Telefono Fijo 2],   [Telefono Movil],  Tarifa, [Fecha WE Entrega], [Fecha WE Pago], [Fecha   Daily]) VALUES ('" & Me.Nombre_Agente & "','" &   Me.Nombre_Cliente & "','" & Me.DNI & "','" &   Me.Nombre_Empresa & "','" & Me.CIF & "','" &   Me.Telefono_Fijo_1 & "','" & Me.Telefono_Fijo_2 & "','"   & Me.Telefono_Movil & "','2.0','" & Me.Fecha_WE_Entrega   & "','" & Me.Fecha_WE_Pago & "','" & Me.Fecha_Daily   & "')"
     End Sub

  7. #7
    Aragan is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jan 2012
    Posts
    22
    Well, the problem is that i was using a bounded Form to the Contratos table, i deleted the bound between the form, table and form fields and now is working perfect! thansk to all who readed this xD!
    ps: dont know how to convert the post to solved XD

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

Similar Threads

  1. INSERT multiple records from form
    By thart21 in forum Forms
    Replies: 5
    Last Post: 02-28-2013, 08:35 AM
  2. Replies: 10
    Last Post: 04-19-2011, 03:38 PM
  3. Replies: 10
    Last Post: 12-13-2010, 11:49 PM
  4. INSERT INTO and UPDATE to multiple tables
    By lupis in forum Import/Export Data
    Replies: 6
    Last Post: 05-19-2010, 05:21 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