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!
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!
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
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:
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!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.![]()
Now i have another problem... the code works but it adds one extra row to the table dont know why...
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? thxCode: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
http://imageshack.us/photo/my-images/827/clipboard02oy.jpg/
![]()
If num20 is 0 or negative the code still inserting 1 row with "Tarifa" field empty... come on... anybody???? >_<
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
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